tsc-esm-fix
Advanced tools
Comparing version 2.7.8 to 2.8.0
{ | ||
"git": { | ||
"commitId": "80fa3306ebfb66a95e472559efed243839b6f4bc", | ||
"commitId": "28c601995c92fa38bfae98c7dce59077b22dc850", | ||
"repoUrl": "https://github.com/antongolub/tsc-esm-fix", | ||
"repoName": "antongolub/tsc-esm-fix" | ||
}, | ||
"date": "2022-03-09T19:07:54.564Z" | ||
"date": "2022-03-31T21:32:58.500Z" | ||
} |
@@ -0,1 +1,8 @@ | ||
# [2.8.0](https://github.com/antongolub/tsc-esm-fix/compare/v2.7.8...v2.8.0) (2022-03-31) | ||
### Features | ||
* introduce `fillBlank` options ([bfe2cb7](https://github.com/antongolub/tsc-esm-fix/commit/bfe2cb7400ca2dd7d81b66b7dccd3bff947305de)) | ||
## [2.7.8](https://github.com/antongolub/tsc-esm-fix/compare/v2.7.7...v2.7.8) (2022-03-09) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "tsc-esm-fix", | ||
"version": "2.7.8", | ||
"version": "2.8.0", | ||
"private": false, | ||
@@ -59,3 +59,3 @@ "publishConfig": { | ||
"globby": "^13.1.1", | ||
"json5": "^2.2.0", | ||
"json5": "^2.2.1", | ||
"meow": "^10.1.2", | ||
@@ -67,18 +67,18 @@ "tslib": "^2.3.1" | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.21", | ||
"cpy-cli": "^4.0.0", | ||
"@types/node": "^17.0.23", | ||
"cpy-cli": "^4.1.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.10.0", | ||
"eslint": "^8.12.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-qiwi": "^1.16.1", | ||
"glob-runner": "^1.0.5", | ||
"glob-runner": "^1.0.6", | ||
"jest": "^27.5.1", | ||
"microbundle": "^0.14.2", | ||
"mkdirp": "^1.0.4", | ||
"prettier": "^2.5.1", | ||
"prettier": "^2.6.1", | ||
"prettier-config-qiwi": "^1.6.1", | ||
"rimraf": "^3.0.2", | ||
"tempy": "^2.0.0", | ||
"terser": "^5.12.0", | ||
"ts-jest": "^27.1.3", | ||
"terser": "^5.12.1", | ||
"ts-jest": "^27.1.4", | ||
"typedoc": "^0.22.13", | ||
@@ -85,0 +85,0 @@ "typescript": "4.6" |
@@ -42,2 +42,3 @@ # tsc-esm-fix | ||
* Searches and replaces `__dirname` and `__filename` refs with `import.meta`. | ||
* Fills blank files with `export {}` (esbuild issue) | ||
* Changes file extensions (applied to local deps only). | ||
@@ -150,14 +151,15 @@ * Supports Windows-based runtimes. | ||
``` | ||
| Option | Description | Default | ||
|---|---|---| | ||
|`--tsconfig`| Path to project's ts-config(s) | `tsconfig.json` | ||
|`--src` | Entry points where the ts-source files are placed. If defined `src` option suppresses `target` | | ||
|`--target` | tsc-compiled output directory | If not specified inherited from tsconfig.json **compilerOptions.outDir** | ||
|`--dirnameVar` | Replace `__dirname` usages with `import.meta` | true | ||
|`--filenameVar` | Replace `__filename` var references with `import.meta` statements | true | ||
|`--ext` | Append extension to relative imports/re-exports | `.js` | ||
|`--unlink` | Remove original files if ext changes | true | ||
|`--cwd`| cwd | `process.cwd()` | ||
|`--out`| Output dir. Defaults to `cwd`, so files would be overwritten | `process.cwd()` | ||
|`--debug` | Prints debug notes | ||
| Option | Description | Default | | ||
|-----------------|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------| | ||
| `--tsconfig` | Path to project's ts-config(s) | `tsconfig.json` | | ||
| `--src` | Entry points where the ts-source files are placed. If defined `src` option suppresses `target` | | ||
| `--target` | tsc-compiled output directory | If not specified inherited from tsconfig.json **compilerOptions.outDir** | | ||
| `--dirnameVar` | Replace `__dirname` usages with `import.meta` | true | | ||
| `--filenameVar` | Replace `__filename` var references with `import.meta` statements | true | | ||
| `--ext` | Append extension to relative imports/re-exports | `.js` | | ||
| `--unlink` | Remove original files if ext changes | true | | ||
| `--fillBlank` | Fill blank files with `export {}` | false | ||
| `--cwd` | cwd | `process.cwd()` | | ||
| `--out` | Output dir. Defaults to `cwd`, so files would be overwritten | `process.cwd()` | | ||
| `--debug` | Prints debug notes | ||
@@ -164,0 +166,0 @@ ### JS/TS API |
@@ -10,3 +10,4 @@ import { IFixOptions, IFixOptionsNormalized } from './interface'; | ||
export declare const fixFilenameVar: (contents: string) => string; | ||
export declare const fixContents: (contents: string, filename: string, filenames: string[], { cwd, ext, dirnameVar, filenameVar }: IFixOptionsNormalized) => string; | ||
export declare const fixBlankFiles: (contents: string) => string; | ||
export declare const fixContents: (contents: string, filename: string, filenames: string[], { cwd, ext, dirnameVar, filenameVar, fillBlank }: IFixOptionsNormalized) => string; | ||
export declare const fix: (opts?: IFixOptions | undefined) => Promise<void>; |
@@ -1,2 +0,2 @@ | ||
export { fix, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, DEFAULT_FIX_OPTIONS, } from './fix'; | ||
export { fix, fixBlankFiles, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, DEFAULT_FIX_OPTIONS, } from './fix'; | ||
export * from './interface'; |
@@ -11,2 +11,3 @@ declare type IFunction<A extends any[] = any[], R = any> = (...args: A) => R; | ||
filenameVar: boolean; | ||
fillBlank?: boolean; | ||
ext: boolean | string; | ||
@@ -13,0 +14,0 @@ unlink?: boolean; |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("path"),require("fs"),require("fs-extra"),require("globby"),require("json5")):"function"==typeof define&&define.amd?define(["exports","path","fs","fs-extra","globby","json5"],n):n((e||self).tscEsmFix={},e.path,e.fs,e.fsExtra,e.globby,e.json5)}(this,function(e,n,r,t,o,u){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=/*#__PURE__*/i(t),l=/*#__PURE__*/i(u);function s(){return s=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},s.apply(this,arguments)}var a=function(e){return r.readFileSync(e,{encoding:"utf8"})},f=function(e){return l.default.parse(a(e))},d=function(e){return e?Array.isArray(e)?e:[e]:[]},m=r.unlinkSync,p=function(e){return e.replace(/\\/g,"/")},g=function e(r){var t=f(r);if(t.extends){var o=e(n.resolve(n.dirname(r),t.extends));return s({},o,{compilerOptions:s({},o.compilerOptions,t.compilerOptions)})}return t},b={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},v=function(e,r){return d(e).reduce(function(e,t){var o,u,i,c=g(n.resolve(r,t)),l=null==c||null==(o=c.compilerOptions)?void 0:o.outDir,s=null==c||null==(u=c.compilerOptions)||null==(i=u.module)?void 0:i.toLowerCase();return!l||"es2020"!==s&&"esnext"!==s||e.push(l),e},[])},y=function(e,n){return e.map(function(e){return e.replace(/\.[^./\\]+$/,n)})},x=function(e,r,t,o){return e.replace(/(\sfrom |\simport[ (])(["'])([^"']+\/[^"']+)(["'])/g,function(e,u,i,c,l){return""+u+i+function(e,r,t,o){var u=n.dirname(e),i=n.resolve(o,"node_modules"),c=/^\..+\.[^./\\]+$/.test(r)?[r,r.replace(/\.[^./\\]+$/,"")]:[r];return[".js",".cjs",".mjs"].reduce(function(e,n){return c.forEach(function(r){return e.push(""+r+n,r+"/index"+n)}),e},[]).find(function(e){return t.includes(p(n.resolve(i,e)))||t.includes(p(n.resolve(u,e)))})||r}(r,c,t,o)+l})},h=function(e){return e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]")},j=function(e){return e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]")},_=function(e,n,r,t){var o=t.dirnameVar,u=t.filenameVar,i=e;return t.ext&&(i=x(i,n,r,t.cwd)),o&&(i=h(i)),u&&(i=j(i)),i};e.DEFAULT_FIX_OPTIONS=b,e.fix=function(e){try{var r=function(e){return s({},b,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:b.debug})}(e),t=r.cwd,u=r.target,i=r.src,l=r.tsconfig,g=r.out,x=r.ext,h=r.debug,j=r.unlink,w=n.resolve(t,void 0===g?t:g),F=d(i),O=[].concat(d(u),v(l,t));h("debug:cwd",t),h("debug:outdir",w),h("debug:sources",F),h("debug:targets",O);var P=F.length>0?F.map(function(e){return e+"/**/*.ts"}):O.map(function(e){return e+"/**/*.js"});return Promise.resolve(o.globby(P,{cwd:t,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return o.globby(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){return e.filter(function(e){return f(e).exports}).map(function(e){return n.basename(n.dirname(e))})})}(e)).then(function(n){return o.globby(["node_modules/**/*.(m|c)?js","!node_modules/.cache","!node_modules/.bin","!node_modules/**/node_modules"].concat(n.map(function(e){return"!node_modules/"+e})),{cwd:e,onlyFiles:!0,absolute:!0})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){h("debug:external-names",n);var o="string"==typeof x?y(e,x):e;h("debug:local-names",o);var u=[].concat(n,o);o.forEach(function(n,o){var l=(i?e[o]:n).replace(p(t),p(w)),s=a(e[o]);!function(e,n){c.default.outputFileSync(e,n,{encoding:"utf8"})}(l,_(s,n,u,r)),!i&&j&&t===w&&l!==e[o]&&m(e[o])})})})}catch(e){return Promise.reject(e)}},e.fixContents=_,e.fixDirnameVar=h,e.fixFilenameExtensions=y,e.fixFilenameVar=j,e.fixModuleReferences=x}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("path"),require("fs"),require("fs-extra"),require("globby"),require("json5")):"function"==typeof define&&define.amd?define(["exports","path","fs","fs-extra","globby","json5"],n):n((e||self).tscEsmFix={},e.path,e.fs,e.fsExtra,e.globby,e.json5)}(this,function(e,n,r,t,o,u){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=/*#__PURE__*/i(t),l=/*#__PURE__*/i(u);function s(){return s=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},s.apply(this,arguments)}var a=function(e){return r.readFileSync(e,{encoding:"utf8"})},f=function(e){return l.default.parse(a(e))},d=function(e){return e?Array.isArray(e)?e:[e]:[]},m=r.unlinkSync,p=function(e){return e.replace(/\\/g,"/")},g=function e(r){var t=f(r);if(t.extends){var o=e(n.resolve(n.dirname(r),t.extends));return s({},o,{compilerOptions:s({},o.compilerOptions,t.compilerOptions)})}return t},b={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},v=function(e,r){return d(e).reduce(function(e,t){var o,u,i,c=g(n.resolve(r,t)),l=null==c||null==(o=c.compilerOptions)?void 0:o.outDir,s=null==c||null==(u=c.compilerOptions)||null==(i=u.module)?void 0:i.toLowerCase();return!l||"es2020"!==s&&"esnext"!==s||e.push(l),e},[])},x=function(e,n){return e.map(function(e){return e.replace(/\.[^./\\]+$/,n)})},y=function(e,r,t,o){return e.replace(/(\sfrom |\simport[ (])(["'])([^"']+\/[^"']+)(["'])/g,function(e,u,i,c,l){return""+u+i+function(e,r,t,o){var u=n.dirname(e),i=n.resolve(o,"node_modules"),c=/^\..+\.[^./\\]+$/.test(r)?[r,r.replace(/\.[^./\\]+$/,"")]:[r];return[".js",".cjs",".mjs"].reduce(function(e,n){return c.forEach(function(r){return e.push(""+r+n,r+"/index"+n)}),e},[]).find(function(e){return t.includes(p(n.resolve(i,e)))||t.includes(p(n.resolve(u,e)))})||r}(r,c,t,o)+l})},h=function(e){return e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]")},j=function(e){return e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]")},_=function(e){return 0===e.trim().length?"\nexport {}\n":e},F=function(e,n,r,t){var o=t.dirnameVar,u=t.filenameVar,i=t.fillBlank,c=e;return t.ext&&(c=y(c,n,r,t.cwd)),o&&(c=h(c)),u&&(c=j(c)),i&&(c=_(c)),c};e.DEFAULT_FIX_OPTIONS=b,e.fix=function(e){try{var r=function(e){return s({},b,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:b.debug})}(e),t=r.cwd,u=r.target,i=r.src,l=r.tsconfig,g=r.out,y=r.ext,h=r.debug,j=r.unlink,_=n.resolve(t,void 0===g?t:g),w=d(i),O=[].concat(d(u),v(l,t));h("debug:cwd",t),h("debug:outdir",_),h("debug:sources",w),h("debug:targets",O);var P=w.length>0?w.map(function(e){return e+"/**/*.ts"}):O.map(function(e){return e+"/**/*.js"});return Promise.resolve(o.globby(P,{cwd:t,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return o.globby(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){return e.filter(function(e){return f(e).exports}).map(function(e){return n.basename(n.dirname(e))})})}(e)).then(function(n){return o.globby(["node_modules/**/*.(m|c)?js","!node_modules/.cache","!node_modules/.bin","!node_modules/**/node_modules"].concat(n.map(function(e){return"!node_modules/"+e})),{cwd:e,onlyFiles:!0,absolute:!0})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){h("debug:external-names",n);var o="string"==typeof y?x(e,y):e;h("debug:local-names",o);var u=[].concat(n,o);o.forEach(function(n,o){var l=(i?e[o]:n).replace(p(t),p(_)),s=a(e[o]);!function(e,n){c.default.outputFileSync(e,n,{encoding:"utf8"})}(l,F(s,n,u,r)),!i&&j&&t===_&&l!==e[o]&&m(e[o])})})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=_,e.fixContents=F,e.fixDirnameVar=h,e.fixFilenameExtensions=x,e.fixFilenameVar=j,e.fixModuleReferences=y}); | ||
//# sourceMappingURL=tsc-esm-fix.umd.js.map |
@@ -10,3 +10,4 @@ import { IFixOptions, IFixOptionsNormalized } from './interface'; | ||
export declare const fixFilenameVar: (contents: string) => string; | ||
export declare const fixContents: (contents: string, filename: string, filenames: string[], { cwd, ext, dirnameVar, filenameVar }: IFixOptionsNormalized) => string; | ||
export declare const fixBlankFiles: (contents: string) => string; | ||
export declare const fixContents: (contents: string, filename: string, filenames: string[], { cwd, ext, dirnameVar, filenameVar, fillBlank }: IFixOptionsNormalized) => string; | ||
export declare const fix: (opts?: IFixOptions | undefined) => Promise<void>; |
@@ -1,2 +0,2 @@ | ||
export { fix, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, DEFAULT_FIX_OPTIONS, } from './fix'; | ||
export { fix, fixBlankFiles, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, DEFAULT_FIX_OPTIONS, } from './fix'; | ||
export * from './interface'; |
@@ -11,2 +11,3 @@ declare type IFunction<A extends any[] = any[], R = any> = (...args: A) => R; | ||
filenameVar: boolean; | ||
fillBlank?: boolean; | ||
ext: boolean | string; | ||
@@ -13,0 +14,0 @@ unlink?: boolean; |
@@ -6,2 +6,3 @@ #!/usr/bin/env node | ||
import { fix } from './fix' | ||
import { IFixOptions } from './interface' | ||
@@ -55,2 +56,5 @@ const cli = meow( | ||
}, | ||
fillBlank: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
@@ -60,2 +64,2 @@ }, | ||
fix(cli.flags) | ||
fix(cli.flags as IFixOptions) |
@@ -0,1 +1,2 @@ | ||
import { Options as GlobbyOptions } from 'globby' | ||
import { basename, dirname, resolve } from 'path' | ||
@@ -107,2 +108,7 @@ | ||
export const fixBlankFiles = (contents: string): string => contents.trim().length === 0 | ||
? ` | ||
export {} | ||
` : contents | ||
export const fixContents = ( | ||
@@ -112,3 +118,3 @@ contents: string, | ||
filenames: string[], | ||
{ cwd, ext, dirnameVar, filenameVar }: IFixOptionsNormalized, | ||
{ cwd, ext, dirnameVar, filenameVar, fillBlank }: IFixOptionsNormalized, | ||
): string => { | ||
@@ -129,2 +135,6 @@ let _contents = contents | ||
if (fillBlank) { | ||
_contents = fixBlankFiles(_contents) | ||
} | ||
return _contents | ||
@@ -138,3 +148,3 @@ } | ||
absolute: true, | ||
}).then((files: string[]) => | ||
} as GlobbyOptions).then((files: string[]) => | ||
files | ||
@@ -160,3 +170,3 @@ .filter((f: string) => readJson(f).exports) | ||
absolute: true, | ||
}, | ||
} as GlobbyOptions, | ||
) | ||
@@ -184,3 +194,3 @@ | ||
absolute: true, | ||
}) | ||
} as GlobbyOptions) | ||
const externalNames = await getExtModules(cwd) | ||
@@ -187,0 +197,0 @@ debug('debug:external-names', externalNames) |
export { | ||
fix, | ||
fixBlankFiles, | ||
fixContents, | ||
@@ -4,0 +5,0 @@ fixFilenameVar, |
@@ -12,2 +12,3 @@ type IFunction<A extends any[] = any[], R = any> = (...args: A) => R | ||
filenameVar: boolean | ||
fillBlank?: boolean | ||
ext: boolean | string | ||
@@ -14,0 +15,0 @@ unlink?: boolean |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91069
652
215
Updatedjson5@^2.2.1