tsc-esm-fix
Advanced tools
Comparing version 2.3.3 to 2.4.0
{ | ||
"git": { | ||
"commitId": "1b9061e1b141d3363075b4b30a6c2eb99bda315e", | ||
"commitId": "625a9cb8bff4f2bd9ad5dc6f1ef05f80743b078b", | ||
"repoUrl": "https://github.com/antongolub/tsc-esm-fix", | ||
"repoName": "antongolub/tsc-esm-fix" | ||
}, | ||
"date": "2021-08-15T16:53:30.943Z" | ||
"date": "2021-08-15T20:36:06.140Z" | ||
} |
@@ -0,1 +1,13 @@ | ||
# [2.4.0](https://github.com/antongolub/tsc-esm-fix/compare/v2.3.3...v2.4.0) (2021-08-15) | ||
### Bug Fixes | ||
* dont add ext prefix for modules that use `exports` pkg.json directive ([31fdb35](https://github.com/antongolub/tsc-esm-fix/commit/31fdb35b9f7541682aaffc7f29a938cdae8724cc)), closes [#24](https://github.com/antongolub/tsc-esm-fix/issues/24) | ||
### Features | ||
* support json5-formatted tsconfigs ([625a9cb](https://github.com/antongolub/tsc-esm-fix/commit/625a9cb8bff4f2bd9ad5dc6f1ef05f80743b078b)), closes [#17](https://github.com/antongolub/tsc-esm-fix/issues/17) | ||
## [2.3.3](https://github.com/antongolub/tsc-esm-fix/compare/v2.3.2...v2.3.3) (2021-08-15) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "tsc-esm-fix", | ||
"version": "2.3.3", | ||
"version": "2.4.0", | ||
"private": false, | ||
@@ -58,2 +58,3 @@ "publishConfig": { | ||
"globby": "^12.0.0", | ||
"json5": "^2.2.0", | ||
"meow": "^10.1.1", | ||
@@ -60,0 +61,0 @@ "tslib": "^2.3.1" |
@@ -90,6 +90,6 @@ # tsc-esm-fix | ||
## Alternatives | ||
https://github.com/mothepro/tsc-esm | ||
https://github.com/digital-loukoum/tsc-esm | ||
* https://github.com/mothepro/tsc-esm | ||
* https://github.com/digital-loukoum/tsc-esm | ||
## License | ||
[MIT](./LICENSE) |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("path"),require("fs"),require("fs-extra"),require("globby")):"function"==typeof define&&define.amd?define(["exports","path","fs","fs-extra","globby"],n):n((e||self).tscEsmFix={},e.path,e.fs,e.fsExtra,e.globby)}(this,function(e,n,r,t,o){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=i(t);function c(){return(c=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}).apply(this,arguments)}var l=function(e){return r.readFileSync(e,{encoding:"utf8"})},s=function(e){return Array.isArray(e)?e:[e]},a=r.unlinkSync,f=function(e){return e.replace(/\\/g,"/")},d=function e(r){var t=function(e){return JSON.parse(l(e))}(r);if(t.extends){var o=e(n.resolve(n.dirname(r),t.extends));return c({},o,{compilerOptions:c({},o.compilerOptions,t.compilerOptions)})}return t},p={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,debug:!1},m=function(e,n){return e.map(function(e){return e.replace(/\.[^.]+$/,n)})},g=function(e,r,t,o){return e.replace(/(\sfrom |\simport[ (])(["'])([^"']+\/[^"']+)(["'])/g,function(e,i,u,c,l){return""+i+u+function(e,r,t,o){var i=n.dirname(e),u=n.resolve(o,"node_modules");return[".js",".cjs",".mjs"].reduce(function(e,n){return e.push(""+r+n,r+"/index"+n),e},[]).find(function(e){return t.includes(f(n.resolve(u,e)))||t.includes(f(n.resolve(i,e)))})||r}(r,c,t,o)+l})},v=function(e){return e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]")},b=function(e){return e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]")},x=function(e,n,r,t){var o=t.dirnameVar,i=t.filenameVar,u=e;return t.ext&&(u=g(u,n,r,t.cwd)),o&&(u=v(u)),i&&(u=b(u)),u};e.DEFAULT_FIX_OPTIONS=p,e.fix=function(e){try{var r=function(e){return c({},p,e)}(e),t=r.cwd,i=r.tsconfig,g=r.out,v=void 0===g?t:g,b=r.ext,y=r.debug?console.log:function(){},h=[].concat(s(r.target),function(e,r){return s(e).reduce(function(e,t){var o,i,u,c=d(n.resolve(r,t)),l=null==c||null==(o=c.compilerOptions)?void 0:o.outDir,s=null==c||null==(i=c.compilerOptions)||null==(u=i.module)?void 0:u.toLowerCase();return!l||"es2020"!==s&&"esnext"!==s||e.push(l),e},[])}(i,t));y("debug:cwd",t),y("debug:targets",h);var j=h.map(function(e){return e+"/**/*.js"}),O=n.resolve(t,v);return y("debug:outdir",O),Promise.resolve(o.globby(j,{cwd:t,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){return o.globby(["node_modules/**/*.(m|c)?js","!node_modules/**/node_modules/**/*.(m|c)?js"],{cwd:e,onlyFiles:!0,absolute:!0})}(t)).then(function(n){y("debug:external-names",n);var o="string"==typeof b?m(e,b):e;y("debug:local-names",o);var i=[].concat(n,o);o.forEach(function(n,o){var c=n.replace(f(t),f(O)),s=l(e[o]);!function(e,n){u.default.outputFileSync(e,n,{encoding:"utf8"})}(c,x(s,n,i,r)),t===O&&c!==e[o]&&a(e[o])})})})}catch(e){return Promise.reject(e)}},e.fixContents=x,e.fixDirnameVar=v,e.fixFilenameExtensions=m,e.fixFilenameVar=b,e.fixRelativeModuleReferences=g}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("path"),require("fs"),require("fs-extra"),require("json5"),require("globby")):"function"==typeof define&&define.amd?define(["exports","path","fs","fs-extra","json5","globby"],n):n((e||self).tscEsmFix={},e.path,e.fs,e.fsExtra,e.json5,e.globby)}(this,function(e,n,r,t,o,u){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=i(t),s=i(o);function l(){return(l=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}).apply(this,arguments)}var a=function(e){return r.readFileSync(e,{encoding:"utf8"})},f=function(e){return s.default.parse(a(e))},d=function(e){return 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 l({},o,{compilerOptions:l({},o.compilerOptions,t.compilerOptions)})}return t},b={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,debug:!1},v=function(e,r){return d(e).reduce(function(e,t){var o,u,i,c=g(n.resolve(r,t)),s=null==c||null==(o=c.compilerOptions)?void 0:o.outDir,l=null==c||null==(u=c.compilerOptions)||null==(i=u.module)?void 0:i.toLowerCase();return!s||"es2020"!==l&&"esnext"!==l||e.push(s),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,s){return""+u+i+function(e,r,t,o){var u=n.dirname(e),i=n.resolve(o,"node_modules");return[".js",".cjs",".mjs"].reduce(function(e,n){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)+s})},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=y(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 l({},b,e)}(e),t=r.cwd,o=r.tsconfig,i=r.out,s=void 0===i?t:i,g=r.ext,y=r.debug?console.log:function(){},h=[].concat(d(r.target),v(o,t));y("debug:cwd",t),y("debug:targets",h);var j=h.map(function(e){return e+"/**/*.js"}),w=n.resolve(t,s);return y("debug:outdir",w),Promise.resolve(u.globby(j,{cwd:t,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return u.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 u.globby(["node_modules/**/*.(m|c)?js","!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){y("debug:external-names",n);var o="string"==typeof g?x(e,g):e;y("debug:local-names",o);var u=[].concat(n,o);o.forEach(function(n,o){var i=n.replace(p(t),p(w)),s=a(e[o]);!function(e,n){c.default.outputFileSync(e,n,{encoding:"utf8"})}(i,_(s,n,u,r)),t===w&&i!==e[o]&&m(e[o])})})})}catch(e){return Promise.reject(e)}},e.fixContents=_,e.fixDirnameVar=h,e.fixFilenameExtensions=x,e.fixFilenameVar=j,e.fixRelativeModuleReferences=y}); | ||
//# sourceMappingURL=tsc-esm-fix.umd.js.map |
@@ -1,5 +0,14 @@ | ||
import { dirname, resolve } from 'path' | ||
import { basename,dirname, resolve } from 'path' | ||
import { IFixOptions, IFixOptionsNormalized } from './interface' | ||
import { asArray, globby, read, resolveTsConfig, unixify, unlink, write } from './util' | ||
import { | ||
asArray, | ||
globby, | ||
read, | ||
readJson, | ||
resolveTsConfig, | ||
unixify, | ||
unlink, | ||
write, | ||
} from './util' | ||
@@ -109,7 +118,21 @@ export const DEFAULT_FIX_OPTIONS: IFixOptionsNormalized = { | ||
const getExtModules = (cwd: string): Promise<string[]> => | ||
const getExtModulesWithExports = (cwd: string): Promise<string[]> => | ||
globby(['node_modules/*/package.json'], { | ||
cwd: cwd, | ||
onlyFiles: true, | ||
absolute: true, | ||
}).then((files: string[]) => | ||
files | ||
.filter((f: string) => readJson(f).exports) | ||
.map((f: string) => basename(dirname(f))), | ||
) | ||
const getExtModules = async (cwd: string): Promise<string[]> => | ||
globby( | ||
[ | ||
'node_modules/**/*.(m|c)?js', | ||
'!node_modules/**/node_modules/**/*.(m|c)?js', | ||
'!node_modules/**/node_modules', | ||
...(await getExtModulesWithExports(cwd)).map( | ||
(m: string) => `!node_modules/${m}`, | ||
), | ||
], | ||
@@ -116,0 +139,0 @@ { |
import { readFileSync, unlinkSync } from 'fs' | ||
import fse from 'fs-extra' | ||
import json5 from 'json5' | ||
import { dirname, resolve } from 'path' | ||
@@ -7,3 +8,3 @@ | ||
export { globby, globbySync }from 'globby' | ||
export { globby, globbySync } from 'globby' | ||
@@ -16,3 +17,3 @@ export const read = (file: string): string => | ||
export const readJson = <D = any>(file: string): D => JSON.parse(read(file)) | ||
export const readJson = <D = any>(file: string): D => json5.parse(read(file)) | ||
@@ -19,0 +20,0 @@ export const asArray = <T>(value: T): T extends any[] ? T : T[] => |
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
72717
555
6
+ Addedjson5@^2.2.0
+ Addedjson5@2.2.3(transitive)