-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tweak distribution bundle and build process
Now files are not compiled into one, each implementation is distributed as separate file. BREAKING CHANGE: now distributed version contained in separate folders: `cjs`, `esm` and `esnext` To include esnext version of package you now have to do `import { cnb } from 'cnbuilder/esnext'`
- Loading branch information
Showing
9 changed files
with
203 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
package-lock.json | ||
node_modules | ||
coverage | ||
dist | ||
cjs | ||
esm | ||
esnext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
.github | ||
coverage | ||
tests | ||
benchmark | ||
src | ||
.idea | ||
.gitignore | ||
.travis.yml | ||
CODE_OF_CONDUCT.md | ||
tsconfig.json | ||
rollup.config.js | ||
* | ||
!/cjs | ||
!/esm | ||
!/esnext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": [ | ||
"src/index.ts" | ||
], | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"outDir": "./cjs", | ||
"declaration": true, | ||
"target": "ES5", | ||
"module": "CommonJS", | ||
"moduleResolution": "Node", | ||
"plugins": [ | ||
{ | ||
"transform": "./utility/ts-transformer-js-ext.ts", | ||
"after": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-default-export */ | ||
import * as ts from 'typescript'; | ||
import * as path from 'path'; | ||
|
||
function shouldUpdateImportDeclaration( | ||
node: ts.Node | ||
): node is (ts.ImportDeclaration | ts.ExportDeclaration) & { moduleSpecifier: ts.StringLiteral } { | ||
if (!ts.isImportDeclaration(node) && !ts.isExportDeclaration(node)) { | ||
return false; | ||
} | ||
if (node.moduleSpecifier === undefined) { | ||
return false; | ||
} | ||
if (!ts.isStringLiteral(node.moduleSpecifier)) { | ||
return false; | ||
} | ||
if (!node.moduleSpecifier.text.startsWith('./') && !node.moduleSpecifier.text.startsWith('../')) { | ||
return false; | ||
} | ||
|
||
return path.extname(node.moduleSpecifier.text) === ''; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export default function transformer(_: ts.Program): ts.TransformerFactory<ts.SourceFile> { | ||
return (context) => (sourceFile) => { | ||
const fac = context.factory; | ||
const visitor = (node: ts.Node): ts.VisitResult<ts.Node> => { | ||
if (shouldUpdateImportDeclaration(node)) { | ||
if (ts.isImportDeclaration(node)) { | ||
const newModuleSpecifier = fac.createStringLiteral(`${node.moduleSpecifier.text}.js`); | ||
return fac.updateImportDeclaration( | ||
node, | ||
node.decorators, | ||
node.modifiers, | ||
node.importClause, | ||
newModuleSpecifier | ||
); | ||
} | ||
if (ts.isExportDeclaration(node)) { | ||
const newModuleSpecifier = fac.createStringLiteral(`${node.moduleSpecifier.text}.js`); | ||
return fac.updateExportDeclaration( | ||
node, | ||
node.decorators, | ||
node.modifiers, | ||
false, | ||
node.exportClause, | ||
newModuleSpecifier | ||
); | ||
} | ||
} | ||
|
||
return ts.visitEachChild(node, visitor, context); | ||
}; | ||
|
||
return ts.visitNode(sourceFile, visitor); | ||
}; | ||
} |
Oops, something went wrong.