@cmmn/tools 1.9.9 → 1.9.11

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.
@@ -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, `/external/${this.options.alias?.[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: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "1.9.9",
3
+ "version": "1.9.11",
4
4
  "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",
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
- // .concat(configs.map(x => [`/external/${x.package}`,
24
- // path.join(x.rootDir, x.outDir ?? `dist/bundle/${x.name}.js`)])),
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('/external/'))
33
+ if (!path.startsWith('/node_modules/'))
34
34
  return null;
35
- return path.substring('/external/'.length);
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 referer = req.headers.referer?.substring(req.headers.origin.length);
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 file = uri2path(await getFileName(name, root));
81
- var stat = fs.statSync(file);
82
- console.info(`Resolve ${name} to ${file}`)
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