inop
v0.7.4
Published
SWC based tool, helps to compile TypeScript modules to Interoperable ESM and CommonJS modules
Downloads
272
Maintainers
Readme
Interoperability
SWC based tool, helps to compile TypeScript code to ESM and CommonJS Interoperable modules.
Usage
Just run build directory
npx inop src build
Use option -p
to adjust package.json
with following changes
{
...
"type": "module",
"main": "build/index.cjs",
"module": "build/index.js",
"types": "build/index.d.ts",
"exports": {
"require": "./build/index.cjs",
"import": "./build/index.js"
},
"files": [ //list build directory and sources for sourceMap
"build",
"src/index.ts"
],
...
}
Use option -i
to ignore specific patterns
npx inop src build -i __tests__ -i __mocks__
As for module declarations and typechecking use the following command, since swc does not support them yet
tsc --declaration --emitDeclarationOnly
Here is the recommended tsconfig.json
{
"compilerOptions": {
...
"target": "ESNext",
"module": "NodeNext",
"declaration": true,
"esModuleInterop": true,
"moduleResolution": "NodeNext",
...
},
...
}
And jest config jest.config.js
export default {
...
coverageProvider: 'v8',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.ts$': '@swc/jest',
},
...
};
Help
Arguments:
source source directory
build build directory
Options:
-V, --version output the version number
-m, --match <match> files match pattern (default: "**/*.ts")
-s, --swcrc <swcrc> swcrc path (default: ".swcrc")
-i, --ignore [ignore...] ignore patterns
-p, --package adjust package.json according to main property
--commonjs-ext [commonjs-ext] file extension of CommonJS files (default: ".cjs")
--esm-ext [esm-ext] file extension of ESM files (default: ".js")
--skip-commonjs do not generate CommonJS files
--skip-esm do not generate ESM files
-h, --help display help for command
License
License The MIT License Copyright (c) 2023-2024 Ivan Zakharchanka