ts-swc-transform 1.12.3 → 1.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/toPath.cjs +9 -1
- package/dist/cjs/toPath.cjs.map +1 -1
- package/dist/esm/toPath.mjs +9 -1
- package/dist/esm/toPath.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/toPath.cjs
CHANGED
|
@@ -19,6 +19,14 @@ function _interop_require_default(obj) {
|
|
|
19
19
|
default: obj
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
var existsSync = function(test) {
|
|
23
|
+
try {
|
|
24
|
+
(_fs.default.accessSync || _fs.default.statSync)(test);
|
|
25
|
+
return true;
|
|
26
|
+
} catch (_) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
22
30
|
function getParentPath(context) {
|
|
23
31
|
if (context.parentPath) return _path.default.dirname(context.parentPath);
|
|
24
32
|
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
|
|
@@ -55,7 +63,7 @@ function toPath(specifier, context) {
|
|
|
55
63
|
var modulePath = _path.default.resolve(pkg.dir, pkg.json.module);
|
|
56
64
|
var mainPath = _path.default.resolve(pkg.dir, pkg.json.main);
|
|
57
65
|
var moduleResolved = _path.default.resolve(modulePath, _path.default.relative(mainPath, main));
|
|
58
|
-
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !
|
|
66
|
+
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;
|
|
59
67
|
}
|
|
60
68
|
return specifier;
|
|
61
69
|
}
|
package/dist/cjs/toPath.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants';\nimport fileURLToPath from './lib/fileURLToPath';\nimport type { Context } from './types';\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.resolve(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.resolve(pkg.dir, pkg.json.module);\n const mainPath = path.resolve(pkg.dir, pkg.json.main);\n const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants';\nimport fileURLToPath from './lib/fileURLToPath';\nimport type { Context } from './types';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.resolve(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.resolve(pkg.dir, pkg.json.module);\n const mainPath = path.resolve(pkg.dir, pkg.json.main);\n const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;\n }\n\n return specifier;\n}\n"],"names":["toPath","existsSync","test","fs","accessSync","statSync","_","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","fileURLToPath","isAbsolute","resolve","moduleRegEx","pkg","main","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace"],"mappings":";;;;+BAsBA;;;eAAwBA;;;yDAtBT;2DACE;iEACM;8DACH;yBACQ;oEACF;;;;;;AAG1B,IAAMC,aAAa,SAACC;IAClB,IAAI;QACDC,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGH;QAC/B,OAAO;IACT,EAAE,OAAOI,GAAG;QACV,OAAO;IACT;AACF;AAEA,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACX,OAAOQ,QA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AO,CAACpB,UAAUqB,OAAO,CAACf,IAAIM,IAAI,CAACG,IAAI,EAAE,OAAO,KAAK,CAAC7B,WAAWgC,kBAAkBX,OAAOW;IAClH;IAEA,OAAOlB;AACT"}
|
package/dist/esm/toPath.mjs
CHANGED
|
@@ -4,6 +4,14 @@ import isAbsolute from 'is-absolute';
|
|
|
4
4
|
import resolve from 'resolve';
|
|
5
5
|
import { moduleRegEx } from './constants.mjs';
|
|
6
6
|
import fileURLToPath from './lib/fileURLToPath.mjs';
|
|
7
|
+
const existsSync = (test)=>{
|
|
8
|
+
try {
|
|
9
|
+
(fs.accessSync || fs.statSync)(test);
|
|
10
|
+
return true;
|
|
11
|
+
} catch (_) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
7
15
|
function getParentPath(context) {
|
|
8
16
|
if (context.parentPath) return path.dirname(context.parentPath);
|
|
9
17
|
return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
|
|
@@ -40,7 +48,7 @@ export default function toPath(specifier, context) {
|
|
|
40
48
|
const modulePath = path.resolve(pkg.dir, pkg.json.module);
|
|
41
49
|
const mainPath = path.resolve(pkg.dir, pkg.json.main);
|
|
42
50
|
const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));
|
|
43
|
-
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !
|
|
51
|
+
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;
|
|
44
52
|
}
|
|
45
53
|
return specifier;
|
|
46
54
|
}
|
package/dist/esm/toPath.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants';\nimport fileURLToPath from './lib/fileURLToPath';\nimport type { Context } from './types';\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.resolve(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.resolve(pkg.dir, pkg.json.module);\n const mainPath = path.resolve(pkg.dir, pkg.json.main);\n const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport isAbsolute from 'is-absolute';\nimport resolve from 'resolve';\nimport { moduleRegEx } from './constants';\nimport fileURLToPath from './lib/fileURLToPath';\nimport type { Context } from './types';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nfunction getParentPath(context: Context) {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context) {\n if (specifier.startsWith('file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.resolve(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n\n let pkg = null;\n const main = resolve.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n packageFilter(json, dir) {\n pkg = { json, dir };\n return json;\n },\n });\n if (!pkg || !pkg.json.module) return main; // no modules, use main\n if (pkg.json.name === specifier) return path.resolve(pkg.dir, pkg.json.module); // the module\n\n // a relative path. Only accept if it doesn't break the relative naming and it exists\n const modulePath = path.resolve(pkg.dir, pkg.json.module);\n const mainPath = path.resolve(pkg.dir, pkg.json.main);\n const moduleResolved = path.resolve(modulePath, path.relative(mainPath, main));\n return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;\n }\n\n return specifier;\n}\n"],"names":["fs","path","isAbsolute","resolve","moduleRegEx","fileURLToPath","existsSync","test","accessSync","statSync","_","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","startsWith","pkg","main","sync","basedir","extensions","packageFilter","json","dir","module","name","modulePath","mainPath","moduleResolved","relative","indexOf","replace"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,aAAa,UAAU;AAC9B,SAASC,WAAW,QAAQ,cAAc;AAC1C,OAAOC,mBAAmB,sBAAsB;AAGhD,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDP,CAAAA,GAAGQ,UAAU,IAAIR,GAAGS,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOZ,KAAKa,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGd,KAAKa,OAAO,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