tsc-esm-fix
Advanced tools
Comparing version 2.20.19 to 2.20.20
{ | ||
"date": "2023-12-30T06:59:51.692Z", | ||
"date": "2023-12-31T09:33:02.831Z", | ||
"git_commit_branch": "master", | ||
"git_commit_id": "b7d1265b1621bfdc272217ca492217b06e8906f0", | ||
"git_commit_id": "6f843cafe979a57f23b400c666a240655f953603", | ||
"git_repo_url": "https://github.com/antongolub/tsc-esm-fix", | ||
"git_repo_name": "antongolub/tsc-esm-fix", | ||
"ci_run_id": "7362675203", | ||
"ci_run_url": "https://github.com/antongolub/tsc-esm-fix/actions/runs/7362675203" | ||
"ci_run_id": "7369646314", | ||
"ci_run_url": "https://github.com/antongolub/tsc-esm-fix/actions/runs/7369646314" | ||
} |
@@ -0,1 +1,6 @@ | ||
## [2.20.20](https://github.com/antongolub/tsc-esm-fix/compare/v2.20.19...v2.20.20) (2023-12-31) | ||
### Fixes & improvements | ||
* fix: use depseek to avoid comments and string literals affects ([6f843ca](https://github.com/antongolub/tsc-esm-fix/commit/6f843cafe979a57f23b400c666a240655f953603)) | ||
## [2.20.19](https://github.com/antongolub/tsc-esm-fix/compare/v2.20.18...v2.20.19) (2023-12-30) | ||
@@ -2,0 +7,0 @@ |
{ | ||
"name": "tsc-esm-fix", | ||
"version": "2.20.19", | ||
"version": "2.20.20", | ||
"private": false, | ||
@@ -49,2 +49,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"depseek": "^0.2.1", | ||
"fs-extra": "^11.2.0", | ||
@@ -51,0 +52,0 @@ "globby": "^13.2.2", |
@@ -40,3 +40,3 @@ # tsc-esm-fix | ||
1. Post-process tsc-compiled outputs each time after build. | ||
2. Patch project sources once as Sindre recommends in [ESM migration guide](https://github.com/sindresorhus/meta/discussions/15) | ||
2. Patch project sources once as Sindre recommends in [the ESM migration guide](https://github.com/sindresorhus/meta/discussions/15) | ||
3. Use [ttypescript](https://github.com/cevek/ttypescript) with [transformer-append-js-ext plugin](https://github.com/Zoltu/typescript-transformer-append-js-extension/) | ||
@@ -56,2 +56,3 @@ | ||
* Injects `.js` extensions into `.d.ts` libdef files | ||
* Does not affect string literals and comments: [depseek](https://github.com/antongolub/misc/tree/master/packages/dep/depseek) | ||
* Handles conditional exports (https://nodejs.org/api/packages.html#conditional-exports) | ||
@@ -58,0 +59,0 @@ * Follows `outDir` found in **tsconfig.json**. |
@@ -0,3 +1,3 @@ | ||
import { TFixer } from '../interface'; | ||
export { fixBlankFiles } from './fix-blank-files'; | ||
export { fixContents } from './fix-contents'; | ||
export { fixFilenameVar, fixDirnameVar } from './fix-dirname-var'; | ||
@@ -7,1 +7,2 @@ export { fixModuleReferences } from './fix-module-ref'; | ||
export { fixDefaultExport } from './fix-default-export'; | ||
export declare const fixContents: TFixer; |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("node:path"),require("fs-extra"),require("json5"),require("globby"),require("node:fs")):"function"==typeof define&&define.amd?define(["exports","node:path","fs-extra","json5","globby","node:fs"],n):n((e||self).tscEsmFix={},e.path,e.fsExtra,e.json5,e.globby,e.node_fs)}(this,function(e,n,t,r,o,u){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=/*#__PURE__*/i(n),c=/*#__PURE__*/i(t),l=/*#__PURE__*/i(r);function a(){return a=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},a.apply(this,arguments)}var f=function(e){var n=e.contents;return a({},e,{contents:0===n.trim().length?"\nexport {}\nexport default undefined\n":n})},d=function(e){var n=e.contents;return a({},e,{contents:n.includes("export default")?n:n+"\nexport default undefined\n"})},m=function(e){return a({},e,{contents:e.contents.replace(/__dirname/g,"`${process.platform === 'win32' ? '' : '/'}${/file:\\/{2,3}(.+)\\/[^/]/.exec(import.meta.url)"+(e.isSource?"!":"")+"[1]}`")})},p=function(e){return a({},e,{contents:e.contents.replace(/__filename/g,"`${process.platform === 'win32' ? '' : '/'}${/file:\\/{2,3}(.+)/.exec(import.meta.url)"+(e.isSource?"!":"")+"[1]}`")})},g=function(e){return c.default.readFileSync(e,{encoding:"utf8"})},v=function(e,n){return c.default.outputFileSync(e,n,{encoding:"utf8"})},b=function(e){return l.default.parse(g(e))},h=function(e){return e?Array.isArray(e)?e:[e]:[]},y=c.default.unlinkSync,x=function(e){return e.replace(/\\/g,"/")},j=function e(t){var r=b(t);if(r.extends){var o=e(n.resolve(n.dirname(t),r.extends));return a({},o,r,{compilerOptions:a({},o.compilerOptions,r.compilerOptions)})}return r},P=function(e){var n=e.filename,t=e.filenames,r=e.options.cwd,o=e.ignore;return a({},e,{contents:e.contents.replace(/((?:\s|^)import\s+|\s+from\s+|\W(?:import|require)\s*\()(["'])([^"']+\/[^"']+|\.{1,2})\/?(["'])/g,function(e,u,i,s,c){return""+u+i+(o.includes(s)?s:M(n,s,t,r))+c})})},M=function(e,t,r,o){var u=n.dirname(e),i=n.resolve(o,"node_modules"),s=/^\..+\.[^./\\]+$/.test(t)?[t,t.replace(/\.[^./\\]+$/,"")]:[t],c=[".js",".cjs",".mjs"].reduce(function(e,n){return s.forEach(function(t){return e.push(""+t+n,t+"/index"+n)}),e},[]);return c.find(function(e){return r.includes(x(n.resolve(u,e)))})||c.find(function(e){return r.includes(x(n.resolve(i,e)))})||t},_=function(e){var t=e.contents,r=e.originName,o=e.filename;return a({},e,{contents:r===o?t:t.replace("//# sourceMappingURL="+n.basename(r)+".map","//# sourceMappingURL="+n.basename(o)+".map")})},w=function(e){var n=e.options,t=e;return n.ext&&(t=P(t)),n.dirnameVar&&(t=m(t)),n.filenameVar&&(t=p(t)),n.fillBlank&&(t=f(t)),n.forceDefaultExport&&(t=d(t)),n.sourceMap&&(t=_(t)),t},O=function(e,t){return h(e).reduce(function(e,r){var o,u,i=j(n.resolve(t,r)),s=null==i||null==(o=i.compilerOptions)?void 0:o.outDir,c=null==i||null==(u=i.compilerOptions)||null==u.module.toLowerCase?void 0:u.module.toLowerCase();return s&&c.startsWith("es")?e.push(s):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),e},[])},S=function(e,t){if(!t)return e;var r=t;return r.includes("*")&&(r=r.slice(0,r.indexOf("*"))).includes("/")&&(r=r.slice(0,r.lastIndexOf("/"))),n.join(e,r)},F={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},k=function(e,n){return e.map(function(e){return e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)})};e.DEFAULT_FIX_OPTIONS=F,e.fix=function(e){try{var t=function(e){return a({},F,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:F.debug})}(e);return Promise.resolve(function(e){try{var t=e.cwd,r=e.target,u=e.src,i=e.tsconfig,c=e.out,l=e.ext,a=e.debug,f=s.default.resolve(t,void 0===c?t:c),d=h(u),m=[].concat(h(r),O(i,t));a("debug:cwd",t),a("debug:outdir",f),a("debug:sources",d),a("debug:targets",m);var p=d.length>0;return Promise.resolve(function(e,n,t){return o.globby(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}"})}(e,n),{cwd:t,onlyFiles:!0,absolute:!0})}(d,m,t)).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return o.globby(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){try{return Promise.resolve(Promise.all(e.map(function(e){try{return Promise.resolve(b(e)).then(function(t){var r=t.name,u=t.exports;if(!u)return{name:r};var i=n.dirname(e),s=function(e){var n=Object.entries(e),t=function e(n){return"string"==typeof n?[n]:Object.values(n).map(e).flat(2)};return"string"!=typeof e&&Object.keys(e).some(function(e){return e.startsWith(".")})?n.map(function(e){return[e[0],t(e[1])]}):[[".",t(e)]]}(u);return Promise.resolve(Promise.all(s.map(function(e){var t=e[0];return Promise.all(e[1].map(function(e){try{return Promise.resolve(o.globby(e,{cwd:i,onlyFiles:!0,absolute:!1})).then(function(o){return o.map(function(o){return n.join(o).replace(S(".",e),S(r,t))})})}catch(e){return Promise.reject(e)}}))}))).then(function(e){return{name:r,files:e.flat(2)}})})}catch(e){return Promise.reject(e)}}))).then(function(e){return e.reduce(function(e,n){var t,r=n.name,o=n.files;return r&&e.names.push(r),o&&(t=e.files).push.apply(t,o),e},{names:[],files:[]})})}catch(e){return Promise.reject(e)}})}(e)).then(function(n){var t=n.names,r=n.files;return Promise.resolve(o.globby(["!node_modules/.cache","!node_modules/.bin","!node_modules/**/node_modules"].concat(t.map(function(e){return"!node_modules/"+e}),["node_modules/**/*.(m|c)?js"]),{cwd:e,onlyFiles:!0,absolute:!0})).then(function(e){return{cjsModules:e,esmModules:r,allPackages:t}})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){var t=n.cjsModules,r=n.esmModules,o=n.allPackages;a("debug:external-cjs-modules",t),a("debug:external-esm-modules",r);var u=[].concat(r,o),i="string"==typeof l?k(e,l):e,s=[].concat(t,i),c=[].concat(t,k(e,".js"));return a("debug:local-modules",i),{outDir:f,isSource:p,ignore:u,allJsModules:c,allModules:s,_localModules:i,localModules:e}})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return Promise.resolve(function(e,n){try{var t=n.cwd,r=n.unlink,o=n.sourceMap,i=e.outDir,c=e.isSource,l=e.ignore,a=e.allJsModules,f=e.allModules,d=e.localModules;return Promise.resolve(Promise.all(e._localModules.map(function(e,m){try{var p=e.endsWith(".d.ts")?a:f,h=d[m],j=(c?h:e).replace(x(t),x(i)),P=g(h),M=w({options:n,contents:P,isSource:c,ignore:l,filename:e,filenames:p,originName:h,nextName:j});return v(j,M.contents),!c&&r&&t===i&&j!==h&&y(h),o&&function(e,n,t){if(void 0===t&&(t=!1),e!==n){var r=e+".map";if(u.existsSync(r)){var o=n+".map",i=b(r);i.file=s.default.basename(n),v(o,JSON.stringify(i)),t&&y(r)}}}(h,j,r&&t===i),Promise.resolve()}catch(e){return Promise.reject(e)}}))).then(function(){})}catch(e){return Promise.reject(e)}}(e,t)).then(function(){})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=function(e){return f({contents:e}).contents},e.fixContents=function(e,n,t,r,o,u,i){return void 0===o&&(o=n),void 0===u&&(u=!1),void 0===i&&(i=[]),w({contents:e,filename:n,filenames:t,options:r,originName:o,isSource:u,ignore:i}).contents},e.fixDefaultExport=function(e){return d({contents:e}).contents},e.fixDirnameVar=function(e,n){return m({contents:e,isSource:n}).contents},e.fixFilenameExtensions=k,e.fixFilenameVar=function(e,n){return p({contents:e,isSource:n}).contents},e.fixModuleReferences=function(e,n,t,r,o){return P({contents:e,filename:n,filenames:t,options:{cwd:r},ignore:o}).contents},e.fixSourceMapRef=function(e,n,t){return _({contents:e,originName:n,filename:t}).contents}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("node:path"),require("fs-extra"),require("json5"),require("globby"),require("node:fs"),require("depseek")):"function"==typeof define&&define.amd?define(["exports","node:path","fs-extra","json5","globby","node:fs","depseek"],n):n((e||self).tscEsmFix={},e.path,e.fsExtra,e.json5,e.globby,e.node_fs,e.depseek)}(this,function(e,n,t,r,o,i,u){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=/*#__PURE__*/s(n),l=/*#__PURE__*/s(t),a=/*#__PURE__*/s(r);function f(){return f=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},f.apply(this,arguments)}function d(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var m=function(e){var n=e.contents;return f({},e,{contents:0===n.trim().length?"\nexport {}\nexport default undefined\n":n})},p=function(e){return f({},e,{contents:e.contents.replace(/__dirname/g,"`${process.platform === 'win32' ? '' : '/'}${/file:\\/{2,3}(.+)\\/[^/]/.exec(import.meta.url)"+(e.isSource?"!":"")+"[1]}`")})},v=function(e){return f({},e,{contents:e.contents.replace(/__filename/g,"`${process.platform === 'win32' ? '' : '/'}${/file:\\/{2,3}(.+)/.exec(import.meta.url)"+(e.isSource?"!":"")+"[1]}`")})},g=function(e){return l.default.readFileSync(e,{encoding:"utf8"})},b=function(e,n){return l.default.outputFileSync(e,n,{encoding:"utf8"})},y=function(e){return a.default.parse(g(e))},h=function(e){return e?Array.isArray(e)?e:[e]:[]},x=l.default.unlinkSync,j=function(e){return e.replace(/\\/g,"/")},P=function e(t){var r=y(t);if(r.extends){var o=e(n.resolve(n.dirname(t),r.extends));return f({},o,r,{compilerOptions:f({},o.compilerOptions,r.compilerOptions)})}return r},S=function(e){for(var n,t=e.contents,r=e.filename,o=e.filenames,i=e.options.cwd,s=e.ignore,c=0,l="",a=function(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return d(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?d(e,n):void 0}}(e))){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(u.depseekSync(t));!(n=a()).done;){var m=n.value,p=m.index,v=m.value,g=v.length,b=v.endsWith("/")?v.slice(0,-1):v,y=!b.includes("/")&&"."!==b&&".."!==b||s.includes(b)?v:w(r,b,o,i);l=l+t.slice(c,p)+y,c=p+g}return f({},e,{contents:l+=t.slice(c)})},w=function(e,t,r,o){var i=n.dirname(e),u=n.resolve(o,"node_modules"),s=/^\..+\.[^./\\]+$/.test(t)?[t,t.replace(/\.[^./\\]+$/,"")]:[t],c=[".js",".cjs",".mjs"].reduce(function(e,n){return s.forEach(function(t){return e.push(""+t+n,t+"/index"+n)}),e},[]);return c.find(function(e){return r.includes(j(n.resolve(i,e)))})||c.find(function(e){return r.includes(j(n.resolve(u,e)))})||t},M=function(e){var t=e.contents,r=e.originName,o=e.filename;return f({},e,{contents:r===o?t:t.replace("//# sourceMappingURL="+n.basename(r)+".map","//# sourceMappingURL="+n.basename(o)+".map")})},O=function(e){var n=e.contents;return f({},e,{contents:n.includes("export default")?n:n+"\nexport default undefined\n"})},_=function(e){var n=e.options,t=e;return n.ext&&(t=S(t)),n.dirnameVar&&(t=p(t)),n.filenameVar&&(t=v(t)),n.fillBlank&&(t=m(t)),n.forceDefaultExport&&(t=O(t)),n.sourceMap&&(t=M(t)),t},k=function(e,t){return h(e).reduce(function(e,r){var o,i,u=P(n.resolve(t,r)),s=null==u||null==(o=u.compilerOptions)?void 0:o.outDir,c=null==u||null==(i=u.compilerOptions)||null==i.module.toLowerCase?void 0:i.module.toLowerCase();return s&&c.startsWith("es")?e.push(s):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),e},[])},F=function(e,t){if(!t)return e;var r=t;return r.includes("*")&&(r=r.slice(0,r.indexOf("*"))).includes("/")&&(r=r.slice(0,r.lastIndexOf("/"))),n.join(e,r)},A={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},D=function(e,n){return e.map(function(e){return e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)})};e.DEFAULT_FIX_OPTIONS=A,e.fix=function(e){try{var t=function(e){return f({},A,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:A.debug})}(e);return Promise.resolve(function(e){try{var t=e.cwd,r=e.target,i=e.src,u=e.tsconfig,s=e.out,l=e.ext,a=e.debug,f=c.default.resolve(t,void 0===s?t:s),d=h(i),m=[].concat(h(r),k(u,t));a("debug:cwd",t),a("debug:outdir",f),a("debug:sources",d),a("debug:targets",m);var p=d.length>0;return Promise.resolve(function(e,n,t){return o.globby(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}"})}(e,n),{cwd:t,onlyFiles:!0,absolute:!0})}(d,m,t)).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return o.globby(["node_modules/*/package.json","node_modules/@*/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){try{return Promise.resolve(Promise.all(e.map(function(e){try{return Promise.resolve(y(e)).then(function(t){var r=t.name,i=t.exports;if(!i)return{name:r};var u=n.dirname(e),s=function(e){var n=Object.entries(e),t=function e(n){return"string"==typeof n?[n]:Object.values(n).map(e).flat(2)};return"string"!=typeof e&&Object.keys(e).some(function(e){return e.startsWith(".")})?n.map(function(e){return[e[0],t(e[1])]}):[[".",t(e)]]}(i);return Promise.resolve(Promise.all(s.map(function(e){var t=e[0];return Promise.all(e[1].map(function(e){try{return Promise.resolve(o.globby(e,{cwd:u,onlyFiles:!0,absolute:!1})).then(function(o){return o.map(function(o){return n.join(o).replace(F(".",e),F(r,t))})})}catch(e){return Promise.reject(e)}}))}))).then(function(e){return{name:r,files:e.flat(2)}})})}catch(e){return Promise.reject(e)}}))).then(function(e){return e.reduce(function(e,n){var t,r=n.name,o=n.files;return r&&e.names.push(r),o&&(t=e.files).push.apply(t,o),e},{names:[],files:[]})})}catch(e){return Promise.reject(e)}})}(e)).then(function(n){var t=n.names,r=n.files;return Promise.resolve(o.globby(["!node_modules/.cache","!node_modules/.bin","!node_modules/**/node_modules"].concat(t.map(function(e){return"!node_modules/"+e}),["node_modules/**/*.(m|c)?js"]),{cwd:e,onlyFiles:!0,absolute:!0})).then(function(e){return{cjsModules:e,esmModules:r,allPackages:t}})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){var t=n.cjsModules,r=n.esmModules,o=n.allPackages;a("debug:external-cjs-modules",t),a("debug:external-esm-modules",r);var i=[].concat(r,o),u="string"==typeof l?D(e,l):e,s=[].concat(t,u),c=[].concat(t,D(e,".js"));return a("debug:local-modules",u),{outDir:f,isSource:p,ignore:i,allJsModules:c,allModules:s,_localModules:u,localModules:e}})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return Promise.resolve(function(e,n){try{var t=n.cwd,r=n.unlink,o=n.sourceMap,u=e.outDir,s=e.isSource,l=e.ignore,a=e.allJsModules,f=e.allModules,d=e.localModules;return Promise.resolve(Promise.all(e._localModules.map(function(e,m){try{var p=e.endsWith(".d.ts")?a:f,v=d[m],h=(s?v:e).replace(j(t),j(u)),P=g(v),S=_({options:n,contents:P,isSource:s,ignore:l,filename:e,filenames:p,originName:v,nextName:h});return b(h,S.contents),!s&&r&&t===u&&h!==v&&x(v),o&&function(e,n,t){if(void 0===t&&(t=!1),e!==n){var r=e+".map";if(i.existsSync(r)){var o=n+".map",u=y(r);u.file=c.default.basename(n),b(o,JSON.stringify(u)),t&&x(r)}}}(v,h,r&&t===u),Promise.resolve()}catch(e){return Promise.reject(e)}}))).then(function(){})}catch(e){return Promise.reject(e)}}(e,t)).then(function(){})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=function(e){return m({contents:e}).contents},e.fixContents=function(e,n,t,r,o,i,u){return void 0===o&&(o=n),void 0===i&&(i=!1),void 0===u&&(u=[]),_({contents:e,filename:n,filenames:t,options:r,originName:o,isSource:i,ignore:u}).contents},e.fixDefaultExport=function(e){return O({contents:e}).contents},e.fixDirnameVar=function(e,n){return p({contents:e,isSource:n}).contents},e.fixFilenameExtensions=D,e.fixFilenameVar=function(e,n){return v({contents:e,isSource:n}).contents},e.fixModuleReferences=function(e,n,t,r,o){return S({contents:e,filename:n,filenames:t,options:{cwd:r},ignore:o}).contents},e.fixSourceMapRef=function(e,n,t){return M({contents:e,originName:n,filename:t}).contents}}); | ||
//# sourceMappingURL=tsc-esm-fix.umd.js.map |
@@ -0,3 +1,3 @@ | ||
import { TFixer } from '../interface.js'; | ||
export { fixBlankFiles } from './fix-blank-files.js'; | ||
export { fixContents } from './fix-contents.js'; | ||
export { fixFilenameVar, fixDirnameVar } from './fix-dirname-var.js'; | ||
@@ -7,1 +7,2 @@ export { fixModuleReferences } from './fix-module-ref.js'; | ||
export { fixDefaultExport } from './fix-default-export.js'; | ||
export declare const fixContents: TFixer; |
import {dirname, resolve} from 'node:path' | ||
import {TFixer} from '../interface' | ||
import {unixify} from '../util' | ||
import { depseekSync } from 'depseek' | ||
export const fixModuleReferences: TFixer = (ctx) => { | ||
const { contents, filename, filenames, options: {cwd}, ignore } = ctx | ||
const _contents = contents.replace( | ||
/((?:\s|^)import\s+|\s+from\s+|\W(?:import|require)\s*\()(["'])([^"']+\/[^"']+|\.{1,2})\/?(["'])/g, | ||
(_matched, control, q1, from, q2) => | ||
`${control}${q1}${ignore.includes(from) ? from : resolveDependency( | ||
filename, | ||
from, | ||
filenames, | ||
cwd, | ||
)}${q2}`, | ||
) | ||
const deps = depseekSync(contents) | ||
let pos = 0 | ||
let _contents = '' | ||
for (const {index, value} of deps) { | ||
const len = value.length | ||
const v = value.endsWith('/') ? value.slice(0, -1) : value | ||
const _value = (v.includes('/') || v === '.' || v === '..') && !ignore.includes(v) | ||
? resolveDependency(filename, v, filenames, cwd) | ||
: value | ||
_contents = _contents + contents.slice(pos, index) + _value | ||
pos = index + len | ||
} | ||
_contents = _contents + contents.slice(pos) | ||
return {...ctx, contents: _contents} | ||
@@ -19,0 +25,0 @@ } |
@@ -0,3 +1,4 @@ | ||
import {TFixer} from '../interface' | ||
export {fixBlankFiles} from './fix-blank-files' | ||
export {fixContents} from './fix-contents' | ||
export {fixFilenameVar, fixDirnameVar} from './fix-dirname-var' | ||
@@ -7,1 +8,29 @@ export {fixModuleReferences} from './fix-module-ref' | ||
export {fixDefaultExport} from './fix-default-export' | ||
import { fixBlankFiles } from './fix-blank-files' | ||
import { fixDefaultExport } from './fix-default-export' | ||
import { fixDirnameVar, fixFilenameVar } from './fix-dirname-var' | ||
import { fixModuleReferences } from './fix-module-ref' | ||
import { fixSourceMapRef } from './fix-sourcemap-ref' | ||
export const fixContents: TFixer = ( | ||
ctx | ||
) => { | ||
const {options} = ctx | ||
let _ctx = ctx | ||
if (options.ext) _ctx = fixModuleReferences(_ctx) | ||
if (options.dirnameVar) _ctx = fixDirnameVar(_ctx) | ||
if (options.filenameVar) _ctx = fixFilenameVar(_ctx) | ||
if (options.fillBlank) _ctx = fixBlankFiles(_ctx) | ||
if (options.forceDefaultExport) _ctx = fixDefaultExport(_ctx) | ||
if (options.sourceMap) _ctx = fixSourceMapRef(_ctx) | ||
return _ctx | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
188605
1275
258
0
6
66
+ Addeddepseek@^0.2.1
+ Addeddepseek@0.2.5(transitive)