@cmmn/tools 1.6.13 → 1.6.17

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.
@@ -14,7 +14,6 @@ import alias from '@rollup/plugin-alias';
14
14
  import replace from '@rollup/plugin-replace';
15
15
  import sourcemaps from 'rollup-plugin-sourcemaps';
16
16
  import {Styles} from "./styles.js";
17
-
18
17
  /**
19
18
  * @typedef {import(rollup).RollupOptions} RollupOptions
20
19
  * @typedef {import(rollup).OutputOptions} OutputOptions
@@ -89,6 +88,10 @@ export class ConfigCreator {
89
88
  assetFileNames: "assets/[name][extname]",
90
89
  chunkFileNames: "chunks/[name].js",
91
90
  name: this.options.global ?? 'global',
91
+ sourcemapPathTransform: sourceMap => {
92
+ const p = path.relative(this.root, path.resolve(this.outDir, sourceMap));
93
+ return path.join('/', this.options.package, p);
94
+ }
92
95
  }));
93
96
  }
94
97
 
@@ -98,19 +101,22 @@ export class ConfigCreator {
98
101
  dir: this.outDir,
99
102
  inject: false,
100
103
  template: (x) => {
101
- const inject = Object.keys(x.bundle.bundle).map(key => {
104
+ let inject = Object.keys(x.bundle.bundle).map(key => {
102
105
  if (key.endsWith('css'))
103
106
  return `<link rel="stylesheet" href="/${key}" >`;
104
107
  if (key.endsWith('js'))
105
108
  return `<script type="module" defer src="/${key}"></script>`;
106
- });
107
- const importMaps = Object.fromEntries(Object.entries(this.options.external)
108
- .map(([key,value]) => [key.replace('.*', '/'), `/external/${value}`]));
109
- const injectImportMaps = `<script type="importmap" >${JSON.stringify({
110
- imports: importMaps
111
- })}</script>`;
109
+ }).join('\n');
110
+ if (!this.options.minify) {
111
+ const importMaps = Object.fromEntries(this.options.external
112
+ .map(key => key.replace('.*', '/'))
113
+ .map(key => [key, `/external/${this.options.alias[key] ?? key}`]));
114
+ inject = `<script type="importmap" >${JSON.stringify({
115
+ imports: importMaps
116
+ })}</script>` + inject;
117
+ }
112
118
  const html = fs.readFileSync(path.join(this.root, this.options.html), 'utf8')
113
- return html.replace('</head>', injectImportMaps + inject.join('\n') + '</head>');
119
+ return html.replace('</head>', inject + '</head>');
114
120
  }
115
121
  });
116
122
  }
@@ -190,12 +196,15 @@ export class ConfigCreator {
190
196
  ];
191
197
  if (this.options.alias) {
192
198
  result.unshift(alias({
193
- entries: this.options.alias
199
+ entries: Object.entries(this.options.alias).map(([key, value]) => ({
200
+ find: key,
201
+ replacement: value
202
+ }))
194
203
  }));
195
- console.log(this.options.alias)
196
204
  }
197
205
  if (this.options.html || this.options.input.endsWith('.html')) {
198
206
  result.push(this.html);
207
+ result.push(watcher([path.join(this.root, this.options.html)]))
199
208
  }
200
209
  if (this.options.stats) {
201
210
  result.push(this.visualizer);
@@ -239,7 +248,7 @@ export class ConfigCreator {
239
248
  [this.options.name]: path.join(this.root, this.options.input)
240
249
  },
241
250
  output: this.output,
242
- external: this.getExternals(),
251
+ external: (this.options.minify && this.options.browser) ? [] : this.getExternals(),
243
252
  manualChunks: this.options.chunks,
244
253
  onwarn(warning) {
245
254
  switch (warning.code) {
@@ -264,8 +273,15 @@ export class ConfigCreator {
264
273
  buildDelay: 300,
265
274
  clearScreen: false,
266
275
  exclude: this.getExternals().concat(path.join(this.root, this.outDir)),
267
- // include: path.join(this.root, 'dist/esm')
268
276
  }
269
277
  }]
270
278
  }
271
279
  }
280
+
281
+ const watcher = (files) => ({
282
+ buildStart() {
283
+ for (const file of files) {
284
+ this.addWatchFile(file);
285
+ }
286
+ },
287
+ });
@@ -1,6 +1,6 @@
1
1
  import ts from "ttypescript";
2
2
  import {resolve, relative} from 'path';
3
-
3
+ import fs from "fs";
4
4
  const rootDir = process.cwd();
5
5
 
6
6
  export function compile(...flags) {
@@ -22,12 +22,18 @@ export function compile(...flags) {
22
22
  builder.clean(rootDir);
23
23
  builder.build(rootDir);
24
24
  }
25
-
25
+ const cleanedBaseDirs = new Set();
26
26
  function createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences) {
27
27
  options.outDir = resolve(options.configFilePath, '../dist/esm');
28
28
  options.declarationDir = resolve(options.configFilePath, '../dist/typings');
29
29
  options.baseUrl = resolve(options.configFilePath, '../');
30
30
  options.tsBuildInfoFile = resolve(options.configFilePath, '../dist/ts.buildinfo');
31
+ if (!cleanedBaseDirs.has(options.baseUrl)){
32
+ fs.rmSync(options.outDir, {recursive: true, force: true});
33
+ fs.rmSync(options.declarationDir, {recursive: true, force: true});
34
+ fs.rmSync(options.tsBuildInfoFile, {force: true});
35
+ cleanedBaseDirs.add(options.baseUrl);
36
+ }
31
37
  console.log('\t', relative(process.cwd(), options.baseUrl));
32
38
  return ts.createEmitAndSemanticDiagnosticsBuilderProgram(
33
39
  rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences
@@ -4,7 +4,7 @@
4
4
  "moduleResolution": "Node",
5
5
  "target": "ES2019",
6
6
  "composite": true,
7
- "sourceMap": true,
7
+ "sourceMap": false,
8
8
  "baseUrl": "./",
9
9
  "experimentalDecorators": true,
10
10
  "checkJs": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "1.6.13",
3
+ "version": "1.6.17",
4
4
  "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",
@@ -81,5 +81,5 @@
81
81
  },
82
82
  "author": "",
83
83
  "license": "ISC",
84
- "gitHead": "4be23c7c2d8afd9f179531b33c32f51fe915e47d"
84
+ "gitHead": "b4664b7dddc9ca6b490b62a922f560d447bb532d"
85
85
  }
@@ -0,0 +1,8 @@
1
+ # serve
2
+ ### запускает сервер, который отдает статический контент
3
+ в бразуер загружаются es-модули как таковые, с import {...} from "some-external-module"
4
+ браузер видит, что ему нужно загрузить еще модули и смотрит в специальный json importmaps который лежит в head. Там маппинг вроде @gm/ -> /external/@gm/ что означает что все модули начинающиеся на @gm/ резолвятся через указанный path.
5
+ serve теперь тоже "умный". Он во-первых "маунтит" все модули из проекта в external, так что /external/@gm/domain-api зарезолвится в (root)/packages/api/dist/bundle/index.js например, и watch этот файл. Во-вторых, на все остальные запросы на /external он начинает резолвить файлы (эта фигня оч противно теперь работает в node) и отдавать js. При этом он их не watch, а просто отдает.
6
+ К чему это привело: все модули загружаются на сайт независимо, а поэтому их можно собирать независимо. Модули маленькие => собираются быстро. Изменения в одном модуле могут не обновлять другие (теоретически, если не изменился .d.ts, но я еще не поборол tsc в этом)
7
+
8
+ **chunk**: react собирается в отдельный чанк => модуль main.js маленький