1.0.1 • Published 5 years ago
@magic-works/commonjs-import.meta v1.0.1
import.meta => __filename
Usage
npm i -D @magic-works/commonjs-import.meta ttypescript typescript ts-node
yarn add -D @magic-works/commonjs-import.meta ttypescript typescript ts-node
pnpm i -D @magic-works/commonjs-import.meta ttypescript typescript ts-nodeThis package works with ttypescript.
Add the following to your tsconfig.json.
{
"compilerOptions": {
"plugins": [{ "transform": "@magic-works/commonjs-import.meta" }]
}
}Use with ts-node in tsconfig.json
{
"ts-node": {
"compilerOptions": {
"module": "CommonJS",
"plugins": [{ "transform": "@magic-works/commonjs-import.meta" }]
},
"compiler": "ttypescript",
// One of:
"ignoreDiagnostics": [1343],
// Or:
"transpileOnly": true
// To mute The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.ts(1343)
}
}Transformation
This transformer did the following thing:
Add the following code to every file:
const __meta = { url: require('url').pathToFileURL(__filename).href }
Object.setPrototypeOf(__meta, null)And it replace every import.meta into __meta.