Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsc-esm-fix

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsc-esm-fix - npm Package Compare versions

Comparing version 2.18.0 to 2.19.0

4

buildstamp.json
{
"git": {
"commitId": "fbf43475b3737ca4c4a4e59d060fe7bb53db23bc",
"commitId": "5bc84c992ce751b84d45f72ad00c24014611d1f3",
"repoUrl": "https://github.com/antongolub/tsc-esm-fix",
"repoName": "antongolub/tsc-esm-fix"
},
"date": "2022-06-06T08:27:51.620Z"
"date": "2022-07-19T11:58:46.236Z"
}

@@ -0,1 +1,8 @@

# [2.19.0](https://github.com/antongolub/tsc-esm-fix/compare/v2.18.0...v2.19.0) (2022-07-19)
### Features
* introdude `forceDefaultExport` directive ([c81b274](https://github.com/antongolub/tsc-esm-fix/commit/c81b274c8ff595183d5d362b86094e5ff515b469))
# [2.18.0](https://github.com/antongolub/tsc-esm-fix/compare/v2.17.3...v2.18.0) (2022-06-06)

@@ -2,0 +9,0 @@

{
"name": "tsc-esm-fix",
"version": "2.18.0",
"version": "2.19.0",
"private": false,

@@ -58,5 +58,5 @@ "publishConfig": {

"fs-extra": "^10.1.0",
"globby": "^13.1.1",
"globby": "^13.1.2",
"json5": "^2.2.1",
"meow": "^10.1.2",
"meow": "^10.1.3",
"tslib": "^2.4.0"

@@ -66,22 +66,22 @@ },

"@qiwi/npm-run-all": "^4.1.7",
"@types/jest": "^28.1.1",
"@types/node": "^17.0.40",
"@types/semver": "^7.3.9",
"@types/jest": "^28.1.6",
"@types/node": "^18.0.6",
"@types/semver": "^7.3.10",
"cpy-cli": "^4.1.0",
"cross-env": "^7.0.3",
"eslint": "^8.17.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-qiwi": "^1.17.1",
"eslint-config-qiwi": "^1.17.3",
"glob-runner": "^1.0.6",
"jest": "^28.1.0",
"jest": "^28.1.3",
"microbundle": "^0.15.0",
"mkdirp": "^1.0.4",
"prettier": "^2.6.2",
"prettier-config-qiwi": "^1.7.1",
"prettier": "^2.7.1",
"prettier-config-qiwi": "^1.7.2",
"rimraf": "^3.0.2",
"semver": "^7.3.7",
"tempy": "^3.0.0",
"terser": "^5.14.0",
"ts-jest": "^28.0.4",
"typedoc": "^0.22.17",
"terser": "^5.14.2",
"ts-jest": "^28.0.7",
"typedoc": "^0.23.8",
"typescript": "4.7"

@@ -88,0 +88,0 @@ },

@@ -170,15 +170,16 @@ # tsc-esm-fix

```
| 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 | |
| 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 |
| `--forceDefaultExport` | Injects `export default undefined` if not present | false |
| `--cwd` | cwd | `process.cwd()` |
| `--out` | Output dir. Defaults to `cwd`, so files would be overwritten | `process.cwd()` |
| `--debug` | Prints debug notes | |

@@ -222,2 +223,3 @@ #### --target vs --src

fillBlank?: boolean
forceDefaultExport?: boolean
ext: boolean | string

@@ -224,0 +226,0 @@ unlink?: boolean,

@@ -10,5 +10,6 @@ import { IFixOptions, IFixOptionsNormalized } from './interface';

export declare const fixFilenameVar: (contents: string) => string;
export declare const fixDefaultExport: (contents: string) => 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 fixContents: (contents: string, filename: string, filenames: string[], { cwd, ext, dirnameVar, filenameVar, fillBlank, forceDefaultExport }: IFixOptionsNormalized) => string;
export declare const getPatterns: (sources: string[], targets: string[]) => string[];
export declare const fix: (opts?: IFixOptions) => Promise<void>;

@@ -1,2 +0,2 @@

export { fix, fixBlankFiles, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, DEFAULT_FIX_OPTIONS, } from './fix';
export { fix, fixBlankFiles, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, fixDefaultExport, DEFAULT_FIX_OPTIONS, } from './fix';
export * from './interface';

@@ -12,2 +12,3 @@ declare type IFunction<A extends any[] = any[], R = any> = (...args: A) => R;

fillBlank?: boolean;
forceDefaultExport?: boolean;
ext: boolean | string;

@@ -14,0 +15,0 @@ unlink?: boolean;

@@ -1,2 +0,2 @@

import{resolve as e,dirname as n,basename as o}from"node:path";import t from"fs-extra";import{globby as r}from"globby";import s from"json5";function l(){return l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e[t]=o[t])}return e},l.apply(this,arguments)}const d=e=>t.readFileSync(e,{encoding:"utf8"}),i=e=>s.parse(d(e)),u=e=>e?Array.isArray(e)?e:[e]:[],a=t.unlinkSync,c=e=>e.replace(/\\/g,"/"),p=o=>{const t=i(o);if(t.extends){const r=p(e(n(o),t.extends));return l({},r,t,{compilerOptions:l({},r.compilerOptions,t.compilerOptions)})}return t},m={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:()=>{}},g=(n,o)=>u(n).reduce((n,t)=>{var r,s;const l=p(e(o,t)),d=null==l||null==(r=l.compilerOptions)?void 0:r.outDir,i=null==l||null==(s=l.compilerOptions)||null==s.module.toLowerCase?void 0:s.module.toLowerCase();return d&&i.startsWith("es")?n.push(d):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),n},[]),f=(e,n)=>e.map(e=>e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)),b=(o,t,r,s)=>o.replace(/(\sfrom\s|[\s(](?:import|require)[ (])(["'])([^"']+\/[^"']+|\.{1,2})(["'])/g,(o,l,d,i,u)=>`${l}${d}${((o,t,r,s)=>{const l=n(o),d=e(s,"node_modules"),i=/^\..+\.[^./\\]+$/.test(t)?[t,t.replace(/\.[^./\\]+$/,"")]:[t],u=[".js",".cjs",".mjs"].reduce((e,n)=>(i.forEach(o=>e.push(`${o}${n}`,`${o}/index${n}`)),e),[]);return u.find(n=>r.includes(c(e(l,n))))||u.find(n=>r.includes(c(e(d,n))))||t})(t,i,r,s)}${u}`),h=e=>e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]"),y=e=>e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]"),w=e=>0===e.trim().length?"\nexport {}\nexport default undefined\n":e,x=(e,n,o,{cwd:t,ext:r,dirnameVar:s,filenameVar:l,fillBlank:d})=>{let i=e;return r&&(i=b(i,n,o,t)),s&&(i=h(i)),l&&(i=y(i)),d&&(i=w(i)),i},$=e=>r(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(e=>e.filter(e=>i(e).exports).map(e=>o(n(e)))),_=async n=>{const o=(e=>l({},m,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:m.debug}))(n),{cwd:s,target:i,src:p,tsconfig:b,out:h=s,ext:y,debug:w,unlink:_}=o,j=e(s,h),v=u(p),O=[...u(i),...g(b,s)];w("debug:cwd",s),w("debug:outdir",j),w("debug:sources",v),w("debug:targets",O);const k=((e,n)=>e.length>0?e.map(e=>e.includes("*")?e:`${e}/**/*.{ts,tsx}`):n.map(e=>e.includes("*")?e:`${e}/**/*.{js,d.ts}`))(v,O),F=await r(k,{cwd:s,onlyFiles:!0,absolute:!0}),V=await(async e=>r(["node_modules/**/*.(m|c)?js","!node_modules/.cache","!node_modules/.bin","!node_modules/**/node_modules",...(await $(e)).map(e=>`!node_modules/${e}`)],{cwd:e,onlyFiles:!0,absolute:!0}))(s);w("debug:external-names",V);const S=[...V,...f(F,".js")],W="string"==typeof y?f(F,y):F,A=[...V,...W];w("debug:local-names",W),W.forEach((e,n)=>{const r=e.endsWith(".d.ts")?S:A,l=(0===v.length?e:F[n]).replace(c(s),c(j)),i=d(F[n]);((e,n)=>{t.outputFileSync(e,n,{encoding:"utf8"})})(l,x(i,e,r,o)),0===v.length&&_&&s===j&&l!==F[n]&&a(F[n])})};export{m as DEFAULT_FIX_OPTIONS,_ as fix,w as fixBlankFiles,x as fixContents,h as fixDirnameVar,f as fixFilenameExtensions,y as fixFilenameVar,b as fixModuleReferences};
import{resolve as e,dirname as n,basename as o}from"node:path";import t from"fs-extra";import{globby as r}from"globby";import l from"json5";function s(){return s=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e[t]=o[t])}return e},s.apply(this,arguments)}const d=e=>t.readFileSync(e,{encoding:"utf8"}),i=e=>l.parse(d(e)),u=e=>e?Array.isArray(e)?e:[e]:[],a=t.unlinkSync,c=e=>e.replace(/\\/g,"/"),p=o=>{const t=i(o);if(t.extends){const r=p(e(n(o),t.extends));return s({},r,t,{compilerOptions:s({},r.compilerOptions,t.compilerOptions)})}return t},m={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:()=>{}},f=(n,o)=>u(n).reduce((n,t)=>{var r,l;const s=p(e(o,t)),d=null==s||null==(r=s.compilerOptions)?void 0:r.outDir,i=null==s||null==(l=s.compilerOptions)||null==l.module.toLowerCase?void 0:l.module.toLowerCase();return d&&i.startsWith("es")?n.push(d):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),n},[]),g=(e,n)=>e.map(e=>e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)),b=(o,t,r,l)=>o.replace(/(\sfrom\s|[\s(](?:import|require)[ (])(["'])([^"']+\/[^"']+|\.{1,2})(["'])/g,(o,s,d,i,u)=>`${s}${d}${((o,t,r,l)=>{const s=n(o),d=e(l,"node_modules"),i=/^\..+\.[^./\\]+$/.test(t)?[t,t.replace(/\.[^./\\]+$/,"")]:[t],u=[".js",".cjs",".mjs"].reduce((e,n)=>(i.forEach(o=>e.push(`${o}${n}`,`${o}/index${n}`)),e),[]);return u.find(n=>r.includes(c(e(s,n))))||u.find(n=>r.includes(c(e(d,n))))||t})(t,i,r,l)}${u}`),h=e=>e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]"),x=e=>e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]"),y=e=>e.includes("export default")?e:`${e}\nexport default undefined\n`,w=e=>0===e.trim().length?"\nexport {}\nexport default undefined\n":e,$=(e,n,o,{cwd:t,ext:r,dirnameVar:l,filenameVar:s,fillBlank:d,forceDefaultExport:i})=>{let u=e;return r&&(u=b(u,n,o,t)),l&&(u=h(u)),s&&(u=x(u)),d&&(u=w(u)),i&&(u=y(u)),u},_=e=>r(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(e=>e.filter(e=>i(e).exports).map(e=>o(n(e)))),j=async n=>{const o=(e=>s({},m,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:m.debug}))(n),{cwd:l,target:i,src:p,tsconfig:b,out:h=l,ext:x,debug:y,unlink:w}=o,j=e(l,h),v=u(p),O=[...u(i),...f(b,l)];y("debug:cwd",l),y("debug:outdir",j),y("debug:sources",v),y("debug:targets",O);const k=((e,n)=>e.length>0?e.map(e=>e.includes("*")?e:`${e}/**/*.{ts,tsx}`):n.map(e=>e.includes("*")?e:`${e}/**/*.{js,d.ts}`))(v,O),F=await r(k,{cwd:l,onlyFiles:!0,absolute:!0}),V=await(async e=>r(["node_modules/**/*.(m|c)?js","!node_modules/.cache","!node_modules/.bin","!node_modules/**/node_modules",...(await _(e)).map(e=>`!node_modules/${e}`)],{cwd:e,onlyFiles:!0,absolute:!0}))(l);y("debug:external-names",V);const D=[...V,...g(F,".js")],E="string"==typeof x?g(F,x):F,S=[...V,...E];y("debug:local-names",E),E.forEach((e,n)=>{const r=e.endsWith(".d.ts")?D:S,s=(0===v.length?e:F[n]).replace(c(l),c(j)),i=d(F[n]);((e,n)=>{t.outputFileSync(e,n,{encoding:"utf8"})})(s,$(i,e,r,o)),0===v.length&&w&&l===j&&s!==F[n]&&a(F[n])})};export{m as DEFAULT_FIX_OPTIONS,j as fix,w as fixBlankFiles,$ as fixContents,y as fixDefaultExport,h as fixDirnameVar,g as fixFilenameExtensions,x as fixFilenameVar,b as fixModuleReferences};
//# sourceMappingURL=tsc-esm-fix.modern.js.map

@@ -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")):"function"==typeof define&&define.amd?define(["exports","node:path","fs-extra","globby","json5"],n):n((e||self).tscEsmFix={},e.node_path,e.fsExtra,e.globby,e.json5)}(this,function(e,n,r,t,o){function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/u(r),c=/*#__PURE__*/u(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},l.apply(this,arguments)}var s=function(e){return i.default.readFileSync(e,{encoding:"utf8"})},a=function(e){return c.default.parse(s(e))},f=function(e){return e?Array.isArray(e)?e:[e]:[]},d=i.default.unlinkSync,m=function(e){return e.replace(/\\/g,"/")},p=function e(r){var t=a(r);if(t.extends){var o=e(n.resolve(n.dirname(r),t.extends));return l({},o,t,{compilerOptions:l({},o.compilerOptions,t.compilerOptions)})}return t},g={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},b=function(e,r){return f(e).reduce(function(e,t){var o,u,i=p(n.resolve(r,t)),c=null==i||null==(o=i.compilerOptions)?void 0:o.outDir,l=null==i||null==(u=i.compilerOptions)||null==u.module.toLowerCase?void 0:u.module.toLowerCase();return c&&l.startsWith("es")?e.push(c):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),e},[])},v=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,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],l=[".js",".cjs",".mjs"].reduce(function(e,n){return c.forEach(function(r){return e.push(""+r+n,r+"/index"+n)}),e},[]);return l.find(function(e){return t.includes(m(n.resolve(u,e)))})||l.find(function(e){return t.includes(m(n.resolve(i,e)))})||r}(r,c,t,o)+l})},x=function(e){return e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]")},y=function(e){return e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]")},j=function(e){return 0===e.trim().length?"\nexport {}\nexport default undefined\n":e},_=function(e,n,r,t){var o=t.dirnameVar,u=t.filenameVar,i=t.fillBlank,c=e;return t.ext&&(c=h(c,n,r,t.cwd)),o&&(c=x(c)),u&&(c=y(c)),i&&(c=j(c)),c};e.DEFAULT_FIX_OPTIONS=g,e.fix=function(e){try{var r=function(e){return l({},g,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:g.debug})}(e),o=r.cwd,u=r.target,c=r.src,p=r.tsconfig,h=r.out,x=r.ext,y=r.debug,j=r.unlink,w=n.resolve(o,void 0===h?o:h),F=f(c),O=[].concat(f(u),b(p,o));y("debug:cwd",o),y("debug:outdir",w),y("debug:sources",F),y("debug:targets",O);var P=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}"})}(F,O);return Promise.resolve(t.globby(P,{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 a(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(n){y("debug:external-names",n);var t=[].concat(n,v(e,".js")),u="string"==typeof x?v(e,x):e,c=[].concat(n,u);y("debug:local-names",u),u.forEach(function(n,u){var l=n.endsWith(".d.ts")?t:c,a=(0===F.length?n:e[u]).replace(m(o),m(w)),f=s(e[u]);!function(e,n){i.default.outputFileSync(e,n,{encoding:"utf8"})}(a,_(f,n,l,r)),0===F.length&&j&&o===w&&a!==e[u]&&d(e[u])})})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=j,e.fixContents=_,e.fixDirnameVar=x,e.fixFilenameExtensions=v,e.fixFilenameVar=y,e.fixModuleReferences=h});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("node:path"),require("fs-extra"),require("globby"),require("json5")):"function"==typeof define&&define.amd?define(["exports","node:path","fs-extra","globby","json5"],n):n((e||self).tscEsmFix={},e.node_path,e.fsExtra,e.globby,e.json5)}(this,function(e,n,t,r,o){function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/u(t),l=/*#__PURE__*/u(o);function c(){return c=Object.assign||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},c.apply(this,arguments)}var s=function(e){return i.default.readFileSync(e,{encoding:"utf8"})},a=function(e){return l.default.parse(s(e))},f=function(e){return e?Array.isArray(e)?e:[e]:[]},d=i.default.unlinkSync,p=function(e){return e.replace(/\\/g,"/")},m=function e(t){var r=a(t);if(r.extends){var o=e(n.resolve(n.dirname(t),r.extends));return c({},o,r,{compilerOptions:c({},o.compilerOptions,r.compilerOptions)})}return r},g={cwd:process.cwd(),tsconfig:"./tsconfig.json",filenameVar:!0,dirnameVar:!0,ext:!0,unlink:!0,debug:function(){}},b=function(e,t){return f(e).reduce(function(e,r){var o,u,i=m(n.resolve(t,r)),l=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 l&&c.startsWith("es")?e.push(l):console.warn("tsconfig should declare `outDir` and `module` type es6 or above"),e},[])},x=function(e,n){return e.map(function(e){return e.endsWith(".d.ts")?e:e.replace(/\.[^./\\]+$/,n)})},v=function(e,t,r,o){return e.replace(/(\sfrom\s|[\s(](?:import|require)[ (])(["'])([^"']+\/[^"']+|\.{1,2})(["'])/g,function(e,u,i,l,c){return""+u+i+function(e,t,r,o){var u=n.dirname(e),i=n.resolve(o,"node_modules"),l=/^\..+\.[^./\\]+$/.test(t)?[t,t.replace(/\.[^./\\]+$/,"")]:[t],c=[".js",".cjs",".mjs"].reduce(function(e,n){return l.forEach(function(t){return e.push(""+t+n,t+"/index"+n)}),e},[]);return c.find(function(e){return r.includes(p(n.resolve(u,e)))})||c.find(function(e){return r.includes(p(n.resolve(i,e)))})||t}(t,l,r,o)+c})},h=function(e){return e.replace(/__dirname/g,"/file:\\/\\/(.+)\\/[^/]/.exec(import.meta.url)[1]")},y=function(e){return e.replace(/__filename/g,"/file:\\/\\/(.+)/.exec(import.meta.url)[1]")},j=function(e){return e.includes("export default")?e:e+"\nexport default undefined\n"},_=function(e){return 0===e.trim().length?"\nexport {}\nexport default undefined\n":e},w=function(e,n,t,r){var o=r.dirnameVar,u=r.filenameVar,i=r.fillBlank,l=r.forceDefaultExport,c=e;return r.ext&&(c=v(c,n,t,r.cwd)),o&&(c=h(c)),u&&(c=y(c)),i&&(c=_(c)),l&&(c=j(c)),c};e.DEFAULT_FIX_OPTIONS=g,e.fix=function(e){try{var t=function(e){return c({},g,e,{debug:"function"==typeof(null==e?void 0:e.debug)?e.debug:!0===(null==e?void 0:e.debug)?console.log:g.debug})}(e),o=t.cwd,u=t.target,l=t.src,m=t.tsconfig,v=t.out,h=t.ext,y=t.debug,j=t.unlink,_=n.resolve(o,void 0===v?o:v),F=f(l),O=[].concat(f(u),b(m,o));y("debug:cwd",o),y("debug:outdir",_),y("debug:sources",F),y("debug:targets",O);var E=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}"})}(F,O);return Promise.resolve(r.globby(E,{cwd:o,onlyFiles:!0,absolute:!0})).then(function(e){return Promise.resolve(function(e){try{return Promise.resolve(function(e){return r.globby(["node_modules/*/package.json"],{cwd:e,onlyFiles:!0,absolute:!0}).then(function(e){return e.filter(function(e){return a(e).exports}).map(function(e){return n.basename(n.dirname(e))})})}(e)).then(function(n){return r.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(n){y("debug:external-names",n);var r=[].concat(n,x(e,".js")),u="string"==typeof h?x(e,h):e,l=[].concat(n,u);y("debug:local-names",u),u.forEach(function(n,u){var c=n.endsWith(".d.ts")?r:l,a=(0===F.length?n:e[u]).replace(p(o),p(_)),f=s(e[u]);!function(e,n){i.default.outputFileSync(e,n,{encoding:"utf8"})}(a,w(f,n,c,t)),0===F.length&&j&&o===_&&a!==e[u]&&d(e[u])})})})}catch(e){return Promise.reject(e)}},e.fixBlankFiles=_,e.fixContents=w,e.fixDefaultExport=j,e.fixDirnameVar=h,e.fixFilenameExtensions=x,e.fixFilenameVar=y,e.fixModuleReferences=v});
//# sourceMappingURL=tsc-esm-fix.umd.js.map

@@ -10,5 +10,6 @@ import { IFixOptions, IFixOptionsNormalized } from './interface.js';

export declare const fixFilenameVar: (contents: string) => string;
export declare const fixDefaultExport: (contents: string) => 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 fixContents: (contents: string, filename: string, filenames: string[], { cwd, ext, dirnameVar, filenameVar, fillBlank, forceDefaultExport }: IFixOptionsNormalized) => string;
export declare const getPatterns: (sources: string[], targets: string[]) => string[];
export declare const fix: (opts?: IFixOptions) => Promise<void>;

@@ -1,2 +0,2 @@

export { fix, fixBlankFiles, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, DEFAULT_FIX_OPTIONS, } from './fix.js';
export { fix, fixBlankFiles, fixContents, fixFilenameVar, fixDirnameVar, fixModuleReferences, fixFilenameExtensions, fixDefaultExport, DEFAULT_FIX_OPTIONS, } from './fix.js';
export * from './interface.js';

@@ -12,2 +12,3 @@ declare type IFunction<A extends any[] = any[], R = any> = (...args: A) => R;

fillBlank?: boolean;
forceDefaultExport?: boolean;
ext: boolean | string;

@@ -14,0 +15,0 @@ unlink?: boolean;

@@ -14,2 +14,4 @@ #!/usr/bin/env node

Options
--out Output dir. Defaults to cwd, so files will be overridden
--cwd cwd. process.cwd() by default
--tsconfig Prod/bundle tsconfig path to search for 'outDir'

@@ -22,4 +24,4 @@ --target Specify target/outDir. Suppresses 'tsconfig.compilerOptions.outDir'.

--filenameVar Replace __filename with import.meta
--out Output dir. Defaults to cwd, so files will be overridden
--cwd cwd. process.cwd() by default
--fillBlank Fill in blank files with 'export {}'
--forceDefaultExport Injects 'export default undefined' if not present

@@ -65,2 +67,5 @@ Examples

},
forceDefaultExport: {
type: 'boolean',
},
},

@@ -67,0 +72,0 @@ },

@@ -111,4 +111,10 @@ import { Options as GlobbyOptions } from 'globby'

export const fixDefaultExport = (contents: string): string => contents.includes('export default')
? contents
: `${contents}
export default undefined
`
export const fixBlankFiles = (contents: string): string => contents.trim().length === 0
? `
? `
export {}

@@ -122,3 +128,3 @@ export default undefined

filenames: string[],
{ cwd, ext, dirnameVar, filenameVar, fillBlank }: IFixOptionsNormalized,
{ cwd, ext, dirnameVar, filenameVar, fillBlank, forceDefaultExport }: IFixOptionsNormalized,
): string => {

@@ -143,2 +149,6 @@ let _contents = contents

if (forceDefaultExport) {
_contents = fixDefaultExport(_contents)
}
return _contents

@@ -145,0 +155,0 @@ }

@@ -9,4 +9,5 @@ export {

fixFilenameExtensions,
fixDefaultExport,
DEFAULT_FIX_OPTIONS,
} from './fix'
export * from './interface'

@@ -13,2 +13,3 @@ type IFunction<A extends any[] = any[], R = any> = (...args: A) => R

fillBlank?: boolean
forceDefaultExport?: boolean
ext: boolean | string

@@ -15,0 +16,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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc