@cmmn/tools 1.9.7 → 1.9.10
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/bundle/esbuild.config.js +4 -1
- package/helpers/getTSConfig.js +19 -0
- package/package.json +6 -5
- package/serve/serve.js +20 -15
package/bundle/esbuild.config.js
CHANGED
|
@@ -59,7 +59,7 @@ export class ConfigCreator {
|
|
|
59
59
|
return JSON.stringify({
|
|
60
60
|
imports: Object.fromEntries(this.options.external
|
|
61
61
|
.map(key => key.replace('*', '/'))
|
|
62
|
-
.map(key => [key, `/
|
|
62
|
+
.map(key => [key, `/node_modules/${this.options.alias?.[key] ?? key}`]))
|
|
63
63
|
})
|
|
64
64
|
}
|
|
65
65
|
getHtmlPlugin(){
|
|
@@ -137,6 +137,9 @@ export class ConfigCreator {
|
|
|
137
137
|
outExtension: {
|
|
138
138
|
'.js': this.getOutExtension(format, platform)
|
|
139
139
|
},
|
|
140
|
+
footer:{
|
|
141
|
+
js: `//# sourceMappingURL=./${this.options.name}.js.map`
|
|
142
|
+
},
|
|
140
143
|
platform: platform,
|
|
141
144
|
tsconfig: 'tsconfig.json',
|
|
142
145
|
external: [
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function getTSConfig(directory = process.cwd()) {
|
|
4
|
+
const configPath = ts.findConfigFile(directory, ts.sys.fileExists, 'tsconfig.json');
|
|
5
|
+
const readConfigFileResult = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
6
|
+
if (readConfigFileResult.error) {
|
|
7
|
+
throw readConfigFileResult.error;
|
|
8
|
+
}
|
|
9
|
+
return readConfigFileResult.config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTSCompilerOptions(directory = process.cwd()) {
|
|
13
|
+
const jsonConfig = getTSConfig(directory);
|
|
14
|
+
const convertResult = ts.convertCompilerOptionsFromJson(jsonConfig.compilerOptions, './');
|
|
15
|
+
if (convertResult.errors && convertResult.errors.length > 0) {
|
|
16
|
+
throw convertResult.errors;
|
|
17
|
+
}
|
|
18
|
+
return convertResult.options;
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmmn/tools",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.10",
|
|
4
4
|
"description": "Compilation, bundling, code generator, testing.",
|
|
5
5
|
"main": "dist/rollup.config.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {},
|
|
14
13
|
"bin": {
|
|
15
14
|
"cmmn": "bin.js"
|
|
16
15
|
},
|
|
@@ -38,7 +37,8 @@
|
|
|
38
37
|
"serve/*",
|
|
39
38
|
"plugins/*",
|
|
40
39
|
"spawn/*",
|
|
41
|
-
"test/*"
|
|
40
|
+
"test/*",
|
|
41
|
+
"helpers/*"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@jest/globals": "27.x.x",
|
|
@@ -63,5 +63,6 @@
|
|
|
63
63
|
},
|
|
64
64
|
"author": "",
|
|
65
65
|
"license": "ISC",
|
|
66
|
-
"gitHead": "2755b333808bf97f1d9454601c2a2c9a88e4a021"
|
|
67
|
-
}
|
|
66
|
+
"gitHead": "2755b333808bf97f1d9454601c2a2c9a88e4a021",
|
|
67
|
+
"scripts": {}
|
|
68
|
+
}
|
package/serve/serve.js
CHANGED
|
@@ -20,8 +20,8 @@ export async function serve(...options) {
|
|
|
20
20
|
watch: configs.map(x => path.join(x.rootDir, x.outDir ?? 'dist/bundle')).join(','),
|
|
21
21
|
mount: x.mount && Object.entries(x.mount)
|
|
22
22
|
.map(([from, to]) => [from, path.resolve(x.rootDir, to)]),
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// .concat(configs.map(x => [`/external/${x.package}`,
|
|
24
|
+
// path.join(x.rootDir, x.outDir ?? `dist/bundle/${x.name}.js`)])),
|
|
25
25
|
proxy: Object.entries(x.proxy ?? {}),
|
|
26
26
|
middleware: [resolveESModule(x.rootDir, configs)].filter(x => x)
|
|
27
27
|
});
|
|
@@ -30,9 +30,9 @@ export async function serve(...options) {
|
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
function getModuleName(path) {
|
|
33
|
-
if (!path.startsWith('/
|
|
33
|
+
if (!path.startsWith('/node_modules/'))
|
|
34
34
|
return null;
|
|
35
|
-
return path.substring('/
|
|
35
|
+
return path.substring('/node_modules/'.length);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const mappingCache = {};
|
|
@@ -41,7 +41,7 @@ async function resolveModule(module, root){
|
|
|
41
41
|
const conditions = ['browser', 'main', 'module', 'import', 'node', 'default'];
|
|
42
42
|
for (let condition of conditions) {
|
|
43
43
|
try {
|
|
44
|
-
return moduleResolve(module, root, new Set([condition]));
|
|
44
|
+
return moduleResolve(module, root, new Set([condition]), true);
|
|
45
45
|
}catch (e){
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -53,12 +53,13 @@ async function getFileName(moduleName, root) {
|
|
|
53
53
|
if (moduleName in mappingCache)
|
|
54
54
|
return mappingCache[moduleName];
|
|
55
55
|
let file;
|
|
56
|
-
if (moduleName.match('\.[cm]?js')) {
|
|
56
|
+
if (moduleName.match('\.[cm]?js(.map)?$')) {
|
|
57
57
|
const module = moduleName.match(/^(@[^/]+\/)?[^/]+/)[0];
|
|
58
58
|
const main = await resolveModule(module, root);
|
|
59
59
|
const file = main.href.replace(new RegExp('node_modules/' + module + '.*$'), 'node_modules/' + moduleName);
|
|
60
60
|
return mappingCache[moduleName] = file;
|
|
61
61
|
} else {
|
|
62
|
+
console.log(moduleName, root);
|
|
62
63
|
const file = await resolveModule(moduleName, root);
|
|
63
64
|
return mappingCache[moduleName] = file.href;
|
|
64
65
|
}
|
|
@@ -66,20 +67,24 @@ async function getFileName(moduleName, root) {
|
|
|
66
67
|
const resolveESModule = (rootDir, configs) => async function (req, res, next) {
|
|
67
68
|
const name = getModuleName(req.url);
|
|
68
69
|
if (!name) {
|
|
69
|
-
console.log(`skip ${req.url}`)
|
|
70
70
|
return next();
|
|
71
71
|
}
|
|
72
72
|
// if (configs.some(x => x.package === name))
|
|
73
73
|
// return next();
|
|
74
|
-
const
|
|
75
|
-
const refererModule = referer && getModuleName(referer);
|
|
76
|
-
const root = refererModule
|
|
77
|
-
? await getFileName(refererModule, 'file://' + rootDir + '/package.json')
|
|
78
|
-
: 'file://' + rootDir + '/package.json';
|
|
74
|
+
const root = 'file://' + process.cwd() + '/package.json';
|
|
79
75
|
try {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
const uri = await getFileName(name, root);
|
|
77
|
+
const file = uri2path(uri);
|
|
78
|
+
const stat = fs.statSync(file);
|
|
79
|
+
const relative = path.relative(rootDir, file).replace(/^.*\/node_modules/, '/node_modules');
|
|
80
|
+
if (req.url !== relative){
|
|
81
|
+
mappingCache[getModuleName(relative)] = uri;
|
|
82
|
+
res.writeHead(302, {
|
|
83
|
+
Location: relative
|
|
84
|
+
});
|
|
85
|
+
res.end();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
83
88
|
res.writeHead(200, {
|
|
84
89
|
'Content-Type': 'application/javascript',
|
|
85
90
|
'Content-Length': stat.size
|