local-lite 2.0.2 → 2.0.3
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/bin/local-lite.mjs +10 -11
- package/package.json +1 -1
package/bin/local-lite.mjs
CHANGED
|
@@ -80,18 +80,9 @@ async function loadModuleExports(filePath) {
|
|
|
80
80
|
return await import(pathToFileURL(absPath).href);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
const requireFromCwd = createRequire(path.join(process.cwd(), 'package.json'));
|
|
83
84
|
try {
|
|
84
|
-
|
|
85
|
-
} catch {
|
|
86
|
-
const requireFromCwd = createRequire(path.join(process.cwd(), 'package.json'));
|
|
87
|
-
let ts;
|
|
88
|
-
try {
|
|
89
|
-
ts = requireFromCwd('typescript');
|
|
90
|
-
} catch {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`Cannot load TypeScript file "${filePath}". Install "typescript" in your project or pass a .js/.mjs/.json file.`,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
85
|
+
const ts = requireFromCwd('typescript');
|
|
95
86
|
const source = await readFile(absPath, 'utf8');
|
|
96
87
|
const transpiled = ts.transpileModule(source, {
|
|
97
88
|
compilerOptions: {
|
|
@@ -108,6 +99,14 @@ async function loadModuleExports(filePath) {
|
|
|
108
99
|
);
|
|
109
100
|
fn.runInThisContext()(moduleObj.exports, () => ({}), moduleObj);
|
|
110
101
|
return moduleObj.exports;
|
|
102
|
+
} catch {
|
|
103
|
+
try {
|
|
104
|
+
return await import(pathToFileURL(absPath).href);
|
|
105
|
+
} catch {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Cannot load TypeScript file "${filePath}". Install "typescript" in your project or pass a .js/.mjs/.json file.`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
|
package/package.json
CHANGED