thunderous-server 0.0.4 → 0.0.5
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/package.json +1 -1
- package/src/build.ts +6 -1
- package/src/generate.ts +18 -1
package/package.json
CHANGED
package/src/build.ts
CHANGED
|
@@ -42,7 +42,12 @@ export const build = () => {
|
|
|
42
42
|
|
|
43
43
|
cpSync(baseDir, outDir, {
|
|
44
44
|
recursive: true,
|
|
45
|
-
filter: (src) =>
|
|
45
|
+
filter: (src) => {
|
|
46
|
+
const name = src.split('/').pop() ?? '';
|
|
47
|
+
if (name.startsWith('_')) return false;
|
|
48
|
+
if (/\.server\.(ts|mts|cts|tsx|js|mjs|cjs|jsx)$/.test(name)) return false;
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
46
51
|
});
|
|
47
52
|
bootstrapThunderous();
|
|
48
53
|
|
package/src/generate.ts
CHANGED
|
@@ -55,11 +55,28 @@ export const bootstrapThunderous = () => {
|
|
|
55
55
|
});
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
/** Rewrite relative import specifiers so the browser can resolve them (e.g. '../theme' → '../theme.js'). */
|
|
59
|
+
const rewriteRelativeImports = (code: string, jsFilePath: string): string =>
|
|
60
|
+
code.replace(
|
|
61
|
+
/((?:^|[\s;,])(?:import|export)\s.*?from\s+['"])([^'"]+)(['"])/gm,
|
|
62
|
+
(_match, prefix: string, spec: string, suffix: string) => {
|
|
63
|
+
if (!spec.startsWith('.')) return `${prefix}${spec}${suffix}`;
|
|
64
|
+
if (/\.[a-z]+$/i.test(spec)) return `${prefix}${spec}${suffix}`;
|
|
65
|
+
const dir = dirname(jsFilePath);
|
|
66
|
+
if (existsSync(join(dir, spec + '.js')) || existsSync(join(dir, spec, 'index.js'))) {
|
|
67
|
+
const resolved = existsSync(join(dir, spec + '.js')) ? spec + '.js' : spec + '/index.js';
|
|
68
|
+
return `${prefix}${resolved}${suffix}`;
|
|
69
|
+
}
|
|
70
|
+
return `${prefix}${spec}.js${suffix}`;
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
58
74
|
/** Transpile a .ts file on disk to .js, writing the output next to it. Returns the .js path. */
|
|
59
75
|
export const transpileTsFile = (tsFilePath: string) => {
|
|
60
76
|
const source = readFileSync(tsFilePath, 'utf-8');
|
|
61
|
-
|
|
77
|
+
let js = transpileTs(source, basename(tsFilePath));
|
|
62
78
|
const jsPath = tsFilePath.replace(/\.ts$/, '.js');
|
|
79
|
+
js = rewriteRelativeImports(js, jsPath);
|
|
63
80
|
writeFileSync(jsPath, js, 'utf-8');
|
|
64
81
|
rmSync(tsFilePath);
|
|
65
82
|
return jsPath;
|