@cmmn/tools 1.4.8 → 1.4.16
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.js +1 -1
- package/bundle/bundle.js +13 -5
- package/bundle/rollup.config.js +51 -11
- package/compile/compile.js +3 -3
- package/package.json +6 -2
package/bin.js
CHANGED
package/bundle/bundle.js
CHANGED
|
@@ -14,8 +14,11 @@ function getProjectConfig(rootDir, cmmn, options) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function getPackageConfigs(rootDir, options, name = null) {
|
|
17
|
+
const pckPath = path.join(rootDir, 'package.json');
|
|
18
|
+
if (!fs.existsSync(pckPath))
|
|
19
|
+
return [];
|
|
17
20
|
const results = [];
|
|
18
|
-
const pkg = JSON.parse(fs.readFileSync(
|
|
21
|
+
const pkg = JSON.parse(fs.readFileSync(pckPath));
|
|
19
22
|
if (name) {
|
|
20
23
|
results.push(...getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
21
24
|
...options,
|
|
@@ -89,16 +92,16 @@ export async function bundle(...options) {
|
|
|
89
92
|
console.log('START BUNDLING');
|
|
90
93
|
break;
|
|
91
94
|
case 'END':
|
|
92
|
-
console.log(
|
|
95
|
+
console.log(`FINISH at ${new Date().toTimeString().substring(0,8)}`);
|
|
93
96
|
break;
|
|
94
97
|
case 'BUNDLE_START':
|
|
95
98
|
for (let key in event.input){
|
|
96
|
-
console.log(
|
|
99
|
+
console.log(`\t${key} -> ${event.output}`);
|
|
97
100
|
}
|
|
98
101
|
break;
|
|
99
102
|
case 'BUNDLE_END':
|
|
100
103
|
for (let key in event.input){
|
|
101
|
-
console.log(
|
|
104
|
+
console.log(`\t${key} -> ${event.output}, (${event.duration / 1000}s)`);
|
|
102
105
|
}
|
|
103
106
|
break;
|
|
104
107
|
|
|
@@ -111,7 +114,10 @@ export async function bundle(...options) {
|
|
|
111
114
|
console.log(`\tline: ${event.error.frame}`);
|
|
112
115
|
break;
|
|
113
116
|
case 'UNRESOLVED_IMPORT':
|
|
114
|
-
console.
|
|
117
|
+
console.warn('UNRESOLVED_IMPORT:\t',event.error.message);
|
|
118
|
+
break;
|
|
119
|
+
case 'MISSING_EXPORT':
|
|
120
|
+
console.warn('MISSING_EXPORT: \t', event.error.message);
|
|
115
121
|
break;
|
|
116
122
|
default:
|
|
117
123
|
console.warn('Unknown error:', event.error.code);
|
|
@@ -119,6 +125,8 @@ export async function bundle(...options) {
|
|
|
119
125
|
break;
|
|
120
126
|
}
|
|
121
127
|
break;
|
|
128
|
+
default:
|
|
129
|
+
console.warn('WARNING:', event)
|
|
122
130
|
}
|
|
123
131
|
});
|
|
124
132
|
}
|
package/bundle/rollup.config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import commonjs from '@rollup/plugin-commonjs';
|
|
2
2
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import image from "rollup-plugin-img";
|
|
3
4
|
import {terser} from "rollup-plugin-terser"
|
|
4
5
|
import {visualizer} from 'rollup-plugin-visualizer';
|
|
5
6
|
import styles from "rollup-plugin-styles";
|
|
@@ -12,6 +13,7 @@ import path from "path";
|
|
|
12
13
|
import html from '@open-wc/rollup-plugin-html';
|
|
13
14
|
import json from '@rollup/plugin-json';
|
|
14
15
|
import alias from '@rollup/plugin-alias';
|
|
16
|
+
import replace from '@rollup/plugin-replace';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* @typedef {import(rollup).RollupOptions} RollupOptions
|
|
@@ -29,6 +31,7 @@ export class ConfigCreator {
|
|
|
29
31
|
* external: string[],
|
|
30
32
|
* stats: boolean,
|
|
31
33
|
* name: string,
|
|
34
|
+
* styles: 'modules' | null,
|
|
32
35
|
* outDir: string,
|
|
33
36
|
* html: string,
|
|
34
37
|
* browser: boolean,
|
|
@@ -80,6 +83,7 @@ export class ConfigCreator {
|
|
|
80
83
|
dir: this.outDir,
|
|
81
84
|
sourcemap: true,
|
|
82
85
|
format: module,
|
|
86
|
+
globals: Array.isArray(this.options.external) ? Object.fromEntries(this.options.external.map(x => [x, x])) : this.options.external,
|
|
83
87
|
name: this.options.global ?? 'global',
|
|
84
88
|
}));
|
|
85
89
|
}
|
|
@@ -124,6 +128,10 @@ export class ConfigCreator {
|
|
|
124
128
|
|
|
125
129
|
get plugins() {
|
|
126
130
|
const result = [
|
|
131
|
+
replace({
|
|
132
|
+
'process.env.NODE_ENV': JSON.stringify('development'),
|
|
133
|
+
preventAssignment: true
|
|
134
|
+
}),
|
|
127
135
|
nodeResolve({
|
|
128
136
|
browser: this.options.browser,
|
|
129
137
|
dedupe: this.options.dedupe || []
|
|
@@ -135,11 +143,28 @@ export class ConfigCreator {
|
|
|
135
143
|
]
|
|
136
144
|
}),
|
|
137
145
|
builtins(),
|
|
138
|
-
styles({
|
|
139
|
-
mode:
|
|
146
|
+
styles(this.options.styles === 'modules' ? {
|
|
147
|
+
mode: [
|
|
148
|
+
"inject",
|
|
149
|
+
{container: "head", prepend: true, attributes: {id: "global"}},
|
|
150
|
+
],
|
|
151
|
+
modules: {
|
|
152
|
+
failOnWrongOrder: true
|
|
153
|
+
},
|
|
154
|
+
namedExports: false,
|
|
155
|
+
autoModules: true,
|
|
156
|
+
}: {
|
|
157
|
+
mode: "emit"
|
|
158
|
+
}),
|
|
159
|
+
image({
|
|
160
|
+
output: `/assets`, // default the root
|
|
161
|
+
extensions: /\.(png|jpg|jpeg|gif)$/, // support png|jpg|jpeg|gif|svg, and it's alse the default value
|
|
162
|
+
limit: 8192, // default 8192(8k)
|
|
163
|
+
exclude: 'node_modules/**'
|
|
140
164
|
}),
|
|
141
165
|
string({
|
|
142
|
-
include: /\.(html|svg|less
|
|
166
|
+
include: /\.(html|svg|less)$/,
|
|
167
|
+
exclude: /\.module\.css/
|
|
143
168
|
}),
|
|
144
169
|
json(),
|
|
145
170
|
|
|
@@ -175,6 +200,14 @@ export class ConfigCreator {
|
|
|
175
200
|
return result;
|
|
176
201
|
}
|
|
177
202
|
|
|
203
|
+
getExternals() {
|
|
204
|
+
if (!this.options.external)
|
|
205
|
+
return [];
|
|
206
|
+
if (Array.isArray(this.options.external))
|
|
207
|
+
return this.options.external.map(s => new RegExp(s));
|
|
208
|
+
return Object.keys(this.options.external).map(s => new RegExp(s));
|
|
209
|
+
}
|
|
210
|
+
|
|
178
211
|
/**
|
|
179
212
|
* @returns {RollupOptions[]}
|
|
180
213
|
*/
|
|
@@ -187,22 +220,29 @@ export class ConfigCreator {
|
|
|
187
220
|
});
|
|
188
221
|
if (this.options.external && typeof this.options.external === "string")
|
|
189
222
|
this.options.external = [this.options.external]
|
|
190
|
-
console.log(this.options);
|
|
223
|
+
console.log(this.options.name, this.options);
|
|
191
224
|
return [{
|
|
192
225
|
input: {
|
|
193
226
|
[this.options.name]: path.join(this.root, this.options.input)
|
|
194
227
|
},
|
|
195
228
|
output: this.output,
|
|
196
|
-
external:
|
|
229
|
+
external: this.getExternals(),
|
|
197
230
|
onwarn(warning) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
231
|
+
switch (warning.code) {
|
|
232
|
+
case 'CIRCULAR_DEPENDENCY':
|
|
233
|
+
return;
|
|
234
|
+
case 'THIS_IS_UNDEFINED':
|
|
235
|
+
console.log(`${warning.message} at`);
|
|
236
|
+
console.log(`\t${warning.id}`);
|
|
237
|
+
break;
|
|
238
|
+
case 'PLUGIN_WARNING':
|
|
239
|
+
console.log(`${warning.message} at`);
|
|
240
|
+
console.log(`\t${warning.id}`);
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
console.warn(`\t${warning.code}(!) ${warning.message}`)
|
|
203
244
|
}
|
|
204
245
|
|
|
205
|
-
console.warn(`(!) ${warning.message}`)
|
|
206
246
|
},
|
|
207
247
|
plugins: this.plugins,
|
|
208
248
|
treeshake: this.options.minify ? "smallest" : "recommended",
|
package/compile/compile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from "ttypescript";
|
|
2
|
-
import {resolve} from 'path';
|
|
2
|
+
import {resolve, relative} from 'path';
|
|
3
3
|
|
|
4
4
|
const rootDir = process.cwd();
|
|
5
5
|
|
|
@@ -16,7 +16,7 @@ export function compile(...flags) {
|
|
|
16
16
|
incremental: true,
|
|
17
17
|
dry: false
|
|
18
18
|
}, {
|
|
19
|
-
excludeDirectories: ["node_modules", "dist"]
|
|
19
|
+
excludeDirectories: ["node_modules", "dist"],
|
|
20
20
|
});
|
|
21
21
|
builder.clean(rootDir);
|
|
22
22
|
builder.build(rootDir);
|
|
@@ -26,7 +26,7 @@ function createProgram(rootNames, options, host, oldProgram, configFileParsingDi
|
|
|
26
26
|
options.outDir = resolve(options.configFilePath, '../dist/esm');
|
|
27
27
|
options.declarationDir = resolve(options.configFilePath, '../dist/typings');
|
|
28
28
|
options.baseUrl = resolve(options.configFilePath, '../');
|
|
29
|
-
console.log('
|
|
29
|
+
console.log('\t', relative(process.cwd(), options.baseUrl));
|
|
30
30
|
return ts.createEmitAndSemanticDiagnosticsBuilderProgram(
|
|
31
31
|
rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences
|
|
32
32
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmmn/tools",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.16",
|
|
4
4
|
"description": "Compilation, bundling, code generator, testing.",
|
|
5
5
|
"main": "dist/rollup.config.js",
|
|
6
6
|
"type": "module",
|
|
@@ -36,11 +36,13 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@jest/globals": "27.x.x",
|
|
39
|
+
"@modular-css/rollup": "28.x.x",
|
|
39
40
|
"@open-wc/rollup-plugin-html": "^1.2.5",
|
|
40
41
|
"@rollup/plugin-alias": "3",
|
|
41
42
|
"@rollup/plugin-commonjs": "^21",
|
|
42
43
|
"@rollup/plugin-json": "4",
|
|
43
44
|
"@rollup/plugin-node-resolve": "^13",
|
|
45
|
+
"@rollup/plugin-replace": "4.x.x",
|
|
44
46
|
"@rollup/plugin-typescript": "^8",
|
|
45
47
|
"@swc/jest": "0.2.17",
|
|
46
48
|
"@testdeck/jest": "0.2.0",
|
|
@@ -50,9 +52,11 @@
|
|
|
50
52
|
"jest": "27.x.x",
|
|
51
53
|
"less": "^4",
|
|
52
54
|
"rollup": "^2",
|
|
55
|
+
"rollup-plugin-img": "1.x.x",
|
|
53
56
|
"rollup-plugin-livereload": "^2.0.5",
|
|
54
57
|
"rollup-plugin-node-builtins": "^2.1.2",
|
|
55
58
|
"rollup-plugin-node-globals": "^1.4.0",
|
|
59
|
+
"rollup-plugin-postcss": "4.x.x",
|
|
56
60
|
"rollup-plugin-serve": "^1.1.0",
|
|
57
61
|
"rollup-plugin-string": "^3.0.0",
|
|
58
62
|
"rollup-plugin-styles": "^4",
|
|
@@ -65,5 +69,5 @@
|
|
|
65
69
|
},
|
|
66
70
|
"author": "",
|
|
67
71
|
"license": "ISC",
|
|
68
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "dec0db17451f8b98d7e10abc3221c567bcddc72d"
|
|
69
73
|
}
|