tsc-esm-fix
Advanced tools
Comparing version 2.20.1 to 2.20.2
{ | ||
"git": { | ||
"commitId": "8950b3bc41e2ea072cd4e80988e985d4017606b1", | ||
"commitId": "8459f27679c2d2d431916669edbb7b62f7d7c57e", | ||
"repoUrl": "https://github.com/antongolub/tsc-esm-fix", | ||
"repoName": "antongolub/tsc-esm-fix" | ||
}, | ||
"date": "2022-08-14T19:11:39.669Z" | ||
"date": "2022-08-14T19:35:08.637Z" | ||
} |
@@ -0,1 +1,8 @@ | ||
## [2.20.2](https://github.com/antongolub/tsc-esm-fix/compare/v2.20.1...v2.20.2) (2022-08-14) | ||
### Performance Improvements | ||
* make stricter `__dirname` and `__filename` subtitutions ([8459f27](https://github.com/antongolub/tsc-esm-fix/commit/8459f27679c2d2d431916669edbb7b62f7d7c57e)), closes [#90](https://github.com/antongolub/tsc-esm-fix/issues/90) | ||
## [2.20.1](https://github.com/antongolub/tsc-esm-fix/compare/v2.20.0...v2.20.1) (2022-08-14) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "tsc-esm-fix", | ||
"version": "2.20.1", | ||
"version": "2.20.2", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("node:path"),require("fs-extra"),require("globby"),require("json5"),require("node:fs")):"function"==typeof define&&define.amd?define(["exports","node:path","fs-extra","globby","json5","node:fs"],n):n((e||self).tscEsmFix={},e.node_path,e.fsExtra,e.globby,e.json5,e.node_fs)}(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(r),a=/*#__PURE__*/i(o);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 l=function(e){return c.default.readFileSync(e,{encoding:"utf8"})},f=function(e,n){return c.default.outputFileSync(e,n,{encoding:"utf8"})},d=function(e){return a.default.parse(l(e))},p=function(e){return e?Array.isArray(e)?e:[e]:[]},m=c.default.unlinkSync,g=function(e){return e.replace(/\\/g,"/")},b=function e(r){var t=d(r);if(t.extends){var o=e(n.resolve(n.dirname(r),t.extends));return s({},o,t,{compilerOptions:s({},o.compilerOptions,t.compilerOptions)})}return t},x={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},v=function(e,r){return p(e).reduce(function(e,t){var o,u,i=b(n.resolve(r,t)),c=null==i||null==(o=i.compilerOptions)?void 0:o.outDir,a=null==i||null==(u=i.compilerOptions)||null==u.module.toLowerCase?void 0:u.module.toLowerCase();return c&&a.startsWith("es")?e.push(c):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),e},[])},y=function(e,n){return e.map(function(e){return e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)})},h=function(e,r,t,o){return e.replace(/(\sfrom\s|[\s(](?:import|require)[ (])(["'])([^"']+\/[^"']+|\.{1,2})\/?(["'])/g,function(e,u,i,c,a){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],a=[".js",".cjs",".mjs"].reduce(function(e,n){return c.forEach(function(r){return e.push(""+r+n,r+"/index"+n)}),e},[]);return a.find(function(e){return t.includes(g(n.resolve(u,e)))})||a.find(function(e){return t.includes(g(n.resolve(i,e)))})||r}(r,c,t,o)+a})},j=function(e){return e.replace(/__dirname/g,"/file:\\/{2,3}(.+)\\/[^/]/.exec(import.meta.url)[1]")},_=function(e){return e.replace(/__filename/g,"/file:\\/{2,3}(.+)/.exec(import.meta.url)[1]")},w=function(e){return e.includes("export default")?e:e+"\nexport default undefined\n"},F=function(e){return 0===e.trim().length?"\nexport {}\nexport default undefined\n":e},O=function(e,r,t){return r===t?e:e.replace("//# sourceMappingURL="+n.basename(r)+".map","//# sourceMappingURL="+n.basename(t)+".map")},E=function(e,n,r,t,o){var u=t.dirnameVar,i=t.filenameVar,c=t.fillBlank,a=t.forceDefaultExport,s=t.sourceMap;void 0===o&&(o=n);var l=e;return t.ext&&(l=h(l,n,r,t.cwd)),u&&(l=j(l)),i&&(l=_(l)),c&&(l=F(l)),a&&(l=w(l)),s&&(l=O(l,o,n)),l};e.DEFAULT_FIX_OPTIONS=x,e.fix=function(e){try{var r=function(e){return s({},x,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:x.debug})}(e),o=r.cwd,i=r.target,c=r.src,a=r.tsconfig,b=r.out,h=r.ext,j=r.debug,_=r.unlink,w=r.sourceMap,F=n.resolve(o,void 0===b?o:b),O=p(c),P=[].concat(p(i),v(a,o));j("debug:cwd",o),j("debug:outdir",F),j("debug:sources",O),j("debug:targets",P);var S=function(e,n){return e.length>0?e.map(function(e){return e.includes("*")?e:e+"/**/*.{ts,tsx}"}):n.map(function(e){return e.includes("*")?e:e+"/**/*.{js,d.ts}"})}(O,P);return Promise.resolve(t.globby(S,{cwd:o,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return t.globby(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){return e.filter(function(e){return d(e).exports}).map(function(e){return n.basename(n.dirname(e))})})}(e)).then(function(n){return t.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)}}(o)).then(function(t){j("debug:external-names",t);var i=[].concat(t,y(e,".js")),c="string"==typeof h?y(e,h):e,a=[].concat(t,c);j("debug:local-names",c),c.forEach(function(t,c){var s=t.endsWith(".d.ts")?i:a,p=e[c],b=(0===O.length?t:p).replace(g(o),g(F)),x=l(p),v=E(x,t,s,r,p);f(b,v),0===O.length&&_&&o===F&&b!==p&&m(p),w&&function(e,r,t){if(void 0===t&&(t=!1),e!==r){var o=e+".map";if(u.existsSync(o)){var i=r+".map",c=d(o);c.file=n.basename(r),f(i,JSON.stringify(c)),t&&m(o)}}}(p,b,_&&o===F)})})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=F,e.fixContents=E,e.fixDefaultExport=w,e.fixDirnameVar=j,e.fixFilenameExtensions=y,e.fixFilenameVar=_,e.fixModuleReferences=h,e.fixSourceMapRef=O}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("node:path"),require("fs-extra"),require("globby"),require("json5"),require("node:fs")):"function"==typeof define&&define.amd?define(["exports","node:path","fs-extra","globby","json5","node:fs"],n):n((e||self).tscEsmFix={},e.node_path,e.fsExtra,e.globby,e.json5,e.node_fs)}(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(r),a=/*#__PURE__*/i(o);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 l=function(e){return c.default.readFileSync(e,{encoding:"utf8"})},f=function(e,n){return c.default.outputFileSync(e,n,{encoding:"utf8"})},d=function(e){return a.default.parse(l(e))},p=function(e){return e?Array.isArray(e)?e:[e]:[]},m=c.default.unlinkSync,g=function(e){return e.replace(/\\/g,"/")},b=function e(r){var t=d(r);if(t.extends){var o=e(n.resolve(n.dirname(r),t.extends));return s({},o,t,{compilerOptions:s({},o.compilerOptions,t.compilerOptions)})}return t},x={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},v=function(e,r){return p(e).reduce(function(e,t){var o,u,i=b(n.resolve(r,t)),c=null==i||null==(o=i.compilerOptions)?void 0:o.outDir,a=null==i||null==(u=i.compilerOptions)||null==u.module.toLowerCase?void 0:u.module.toLowerCase();return c&&a.startsWith("es")?e.push(c):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),e},[])},y=function(e,n){return e.map(function(e){return e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)})},h=function(e,r,t,o){return e.replace(/(\sfrom\s|[\s(](?:import|require)[ (])(["'])([^"']+\/[^"']+|\.{1,2})\/?(["'])/g,function(e,u,i,c,a){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],a=[".js",".cjs",".mjs"].reduce(function(e,n){return c.forEach(function(r){return e.push(""+r+n,r+"/index"+n)}),e},[]);return a.find(function(e){return t.includes(g(n.resolve(u,e)))})||a.find(function(e){return t.includes(g(n.resolve(i,e)))})||r}(r,c,t,o)+a})},j=function(e){return e.replace(/__dirname/g,"(/file:\\/{2,3}(.+)\\/[^/]/.exec(import.meta.url) || [])[1]")},_=function(e){return e.replace(/__filename/g,"(/file:\\/{2,3}(.+)/.exec(import.meta.url) || [])[1]")},w=function(e){return e.includes("export default")?e:e+"\nexport default undefined\n"},F=function(e){return 0===e.trim().length?"\nexport {}\nexport default undefined\n":e},O=function(e,r,t){return r===t?e:e.replace("//# sourceMappingURL="+n.basename(r)+".map","//# sourceMappingURL="+n.basename(t)+".map")},E=function(e,n,r,t,o){var u=t.dirnameVar,i=t.filenameVar,c=t.fillBlank,a=t.forceDefaultExport,s=t.sourceMap;void 0===o&&(o=n);var l=e;return t.ext&&(l=h(l,n,r,t.cwd)),u&&(l=j(l)),i&&(l=_(l)),c&&(l=F(l)),a&&(l=w(l)),s&&(l=O(l,o,n)),l};e.DEFAULT_FIX_OPTIONS=x,e.fix=function(e){try{var r=function(e){return s({},x,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:x.debug})}(e),o=r.cwd,i=r.target,c=r.src,a=r.tsconfig,b=r.out,h=r.ext,j=r.debug,_=r.unlink,w=r.sourceMap,F=n.resolve(o,void 0===b?o:b),O=p(c),P=[].concat(p(i),v(a,o));j("debug:cwd",o),j("debug:outdir",F),j("debug:sources",O),j("debug:targets",P);var S=function(e,n){return e.length>0?e.map(function(e){return e.includes("*")?e:e+"/**/*.{ts,tsx}"}):n.map(function(e){return e.includes("*")?e:e+"/**/*.{js,d.ts}"})}(O,P);return Promise.resolve(t.globby(S,{cwd:o,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return t.globby(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){return e.filter(function(e){return d(e).exports}).map(function(e){return n.basename(n.dirname(e))})})}(e)).then(function(n){return t.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)}}(o)).then(function(t){j("debug:external-names",t);var i=[].concat(t,y(e,".js")),c="string"==typeof h?y(e,h):e,a=[].concat(t,c);j("debug:local-names",c),c.forEach(function(t,c){var s=t.endsWith(".d.ts")?i:a,p=e[c],b=(0===O.length?t:p).replace(g(o),g(F)),x=l(p),v=E(x,t,s,r,p);f(b,v),0===O.length&&_&&o===F&&b!==p&&m(p),w&&function(e,r,t){if(void 0===t&&(t=!1),e!==r){var o=e+".map";if(u.existsSync(o)){var i=r+".map",c=d(o);c.file=n.basename(r),f(i,JSON.stringify(c)),t&&m(o)}}}(p,b,_&&o===F)})})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=F,e.fixContents=E,e.fixDefaultExport=w,e.fixDirnameVar=j,e.fixFilenameExtensions=y,e.fixFilenameVar=_,e.fixModuleReferences=h,e.fixSourceMapRef=O}); | ||
//# sourceMappingURL=tsc-esm-fix.umd.js.map |
@@ -106,7 +106,7 @@ import { Options as GlobbyOptions } from 'globby' | ||
/__dirname/g, | ||
'/file:\\/{2,3}(.+)\\/[^/]/.exec(import.meta.url)[1]', | ||
'(/file:\\/{2,3}(.+)\\/[^/]/.exec(import.meta.url) || [])[1]', | ||
) // eslint-disable-line | ||
export const fixFilenameVar = (contents: string): string => | ||
contents.replace(/__filename/g, '/file:\\/{2,3}(.+)/.exec(import.meta.url)[1]') // eslint-disable-line | ||
contents.replace(/__filename/g, '(/file:\\/{2,3}(.+)/.exec(import.meta.url) || [])[1]') // eslint-disable-line | ||
@@ -113,0 +113,0 @@ export const fixDefaultExport = (contents: string): string => contents.includes('export default') |
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
118372