Skip to content

Commit

Permalink
Handle types export in ESM
Browse files Browse the repository at this point in the history
Closes #216.
  • Loading branch information
niksy committed Mar 23, 2024
1 parent b259590 commit a9f89d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "<% if ( sassModule ) { %>_index.scss<% } else if ( cssModule ) { %>index.css<% } else { %><% if ( transpile ) { %><% if ( bundleCjs ) { %>cjs/<% } else { %>esm/<% } %><% } %>index.js<% } %>",
"module": "<% if ( transpile ) { %>esm/<% } %>index.js",
"exports": {
".": {<% if ( browserModule && styles || sassModule || cssModule ) { %><% if ( sassModule ) { %>
".": {<% if ( typescript ) { %>
"types": "<% if ( transpile ) { %>esm/<% } %>index.d.ts",<% } %><% if ( browserModule && styles || sassModule || cssModule ) { %><% if ( sassModule ) { %>
"sass": "./_index.scss",<% } %>
"style": "./<% if ( sassModule ) { %>_index.scss<% } else if ( cssModule ) { %>index.css<% } else { %><% if ( transpile ) { %>dist/<% } %>index.css<% } %>",<% } %>
"import": "./<% if ( transpile ) { %>esm/<% } %>index.js"<% if ( bundleCjs ) { %>,
Expand Down Expand Up @@ -143,7 +144,7 @@
"eslint-plugin-html": "^6.0.0",
"rollup-plugin-svelte": "^7.2.0",
"svelte": "^2.16.1"<% } %><% if ( typescript ) { %>,
"typescript": "^4.3.5",
"typescript": "^5.4.3",
"cpy": "^8.1.2",
"execa": "^5.1.1",<% if ( !transpile && typescriptMode === 'full' && (!browserModule || (browserModule && integrationTests)) ) { %>
"ts-node": "^10.1.0",<% } %><% if ( browserModule && usesHtmlFixtures ) { %>
Expand All @@ -167,6 +168,5 @@
"bugs": {
"url": "https://<%= gitRepo.host %>/<%= gitRepo.repository %>/issues"
},
"homepage": "https://<%= gitRepo.host %>/<%= gitRepo.repository %>#readme"<% if ( typescript ) { %>,
"types": "<% if ( transpile ) { %>esm/<% } %>index.d.ts"<% } %>
"homepage": "https://<%= gitRepo.host %>/<%= gitRepo.repository %>#readme"
}
11 changes: 6 additions & 5 deletions generators/app/templates/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"lib": ["ESNext"<% if ( browserModule ) { %>, "DOM"<% } %>],
"moduleResolution": "node",
"target": "ES2022",
"module": "node16",
"lib": ["ES2022"<% if ( browserModule ) { %>, "DOM"<% } %>],
"moduleResolution": "node16",
"moduleDetection": "force",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"resolveJsonModule": false,
"noEmit": true,
"newLine": "lf",
"strict": true,
Expand Down
8 changes: 6 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1470,12 +1470,16 @@ describe('TypeScript, with comments', function () {

it('should fill package.json with correct information', function () {
assert.jsonFileContent('package.json', {
types: 'esm/index.d.ts',
exports: {
'.': {
types: 'esm/index.d.ts'
}
},
scripts: {
'lint:types': 'tsc'
},
devDependencies: {
'typescript': '^4.3.5',
'typescript': '^5.4.3',
'@types/node': '^16.3.0',
'@types/mocha': '^10.0.6'
}
Expand Down

0 comments on commit a9f89d7

Please sign in to comment.