@cmmn/tools 1.4.13 → 1.5.0

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/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(path.join(rootDir, 'package.json')));
21
+ const pkg = JSON.parse(fs.readFileSync(pckPath));
19
22
  if (name) {
20
23
  results.push(...getProjectConfig(rootDir, pkg.cmmn[name], {
21
24
  ...options,
@@ -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.error(event.error.message);
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);
@@ -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,7 +13,10 @@ 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';
17
+ import postCSS from "rollup-plugin-postcss"
15
18
 
19
+ import flexbugs from 'postcss-flexbugs-fixes';
16
20
  /**
17
21
  * @typedef {import(rollup).RollupOptions} RollupOptions
18
22
  * @typedef {import(rollup).OutputOptions} OutputOptions
@@ -29,6 +33,7 @@ export class ConfigCreator {
29
33
  * external: string[],
30
34
  * stats: boolean,
31
35
  * name: string,
36
+ * styles: 'modules' | null,
32
37
  * outDir: string,
33
38
  * html: string,
34
39
  * browser: boolean,
@@ -80,7 +85,7 @@ export class ConfigCreator {
80
85
  dir: this.outDir,
81
86
  sourcemap: true,
82
87
  format: module,
83
- globals: Object.fromEntries(this.options.external.map(x => [x,x])),
88
+ globals: Array.isArray(this.options.external) ? Object.fromEntries(this.options.external.map(x => [x, x])) : this.options.external,
84
89
  name: this.options.global ?? 'global',
85
90
  }));
86
91
  }
@@ -125,6 +130,10 @@ export class ConfigCreator {
125
130
 
126
131
  get plugins() {
127
132
  const result = [
133
+ replace({
134
+ 'process.env.NODE_ENV': JSON.stringify('development'),
135
+ preventAssignment: true
136
+ }),
128
137
  nodeResolve({
129
138
  browser: this.options.browser,
130
139
  dedupe: this.options.dedupe || []
@@ -136,11 +145,31 @@ export class ConfigCreator {
136
145
  ]
137
146
  }),
138
147
  builtins(),
139
- styles({
140
- mode: "emit",
148
+ this.options.styles === 'modules' ? postCSS({
149
+ mode: [
150
+ "inject",
151
+ {container: "head", prepend: true, attributes: {id: "global"}},
152
+ ],
153
+ plugins: [
154
+ flexbugs,
155
+ ],
156
+ modules: {
157
+ root: ''
158
+ },
159
+ namedExports: false,
160
+ autoModules: true,
161
+ }) : styles({
162
+ mode: "emit"
163
+ }),
164
+ image({
165
+ output: `/assets`, // default the root
166
+ extensions: /\.(png|jpg|jpeg|gif)$/, // support png|jpg|jpeg|gif|svg, and it's alse the default value
167
+ limit: 8192, // default 8192(8k)
168
+ exclude: 'node_modules/**'
141
169
  }),
142
170
  string({
143
- include: /\.(html|svg|less|css)$/,
171
+ include: /\.(html|svg|less)$/,
172
+ exclude: /\.module\.css/
144
173
  }),
145
174
  json(),
146
175
 
@@ -176,6 +205,14 @@ export class ConfigCreator {
176
205
  return result;
177
206
  }
178
207
 
208
+ getExternals() {
209
+ if (!this.options.external)
210
+ return [];
211
+ if (Array.isArray(this.options.external))
212
+ return this.options.external.map(s => new RegExp(s));
213
+ return Object.keys(this.options.external).map(s => new RegExp(s));
214
+ }
215
+
179
216
  /**
180
217
  * @returns {RollupOptions[]}
181
218
  */
@@ -188,23 +225,27 @@ export class ConfigCreator {
188
225
  });
189
226
  if (this.options.external && typeof this.options.external === "string")
190
227
  this.options.external = [this.options.external]
191
- console.log(this.options);
228
+ console.log(this.options.name, this.options);
192
229
  return [{
193
230
  input: {
194
231
  [this.options.name]: path.join(this.root, this.options.input)
195
232
  },
196
233
  output: this.output,
197
- external: (this.options.external || []),
234
+ external: this.getExternals(),
198
235
  onwarn(warning) {
199
- switch (warning.code){
236
+ switch (warning.code) {
200
237
  case 'CIRCULAR_DEPENDENCY':
201
238
  return;
202
239
  case 'THIS_IS_UNDEFINED':
203
240
  console.log(`${warning.message} at`);
204
241
  console.log(`\t${warning.id}`);
205
242
  break;
243
+ case 'PLUGIN_WARNING':
244
+ console.log(`${warning.message} at`);
245
+ console.log(`\t${warning.id}`);
246
+ break;
206
247
  default:
207
- console.warn(`\t(!) ${warning.message}`)
248
+ console.warn(`\t${warning.code}(!) ${warning.message}`)
208
249
  }
209
250
 
210
251
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "1.4.13",
3
+ "version": "1.5.0",
4
4
  "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",
@@ -36,28 +36,37 @@
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",
47
49
  "@types/jest": "27.x.x",
50
+ "@types/sinon": "10.x.x",
48
51
  "@web/rollup-plugin-html": "^1.10.1",
49
52
  "fast-glob": "^3.2.11",
50
53
  "jest": "27.x.x",
51
54
  "less": "^4",
55
+ "postcss-composes": "^0.1.0",
56
+ "postcss-flexbugs-fixes": "5.x.x",
57
+ "postcss-normalize": "10.x.x",
52
58
  "rollup": "^2",
59
+ "rollup-plugin-img": "1.x.x",
53
60
  "rollup-plugin-livereload": "^2.0.5",
54
61
  "rollup-plugin-node-builtins": "^2.1.2",
55
62
  "rollup-plugin-node-globals": "^1.4.0",
63
+ "rollup-plugin-postcss": "4.x.x",
56
64
  "rollup-plugin-serve": "^1.1.0",
57
65
  "rollup-plugin-string": "^3.0.0",
58
66
  "rollup-plugin-styles": "^4",
59
67
  "rollup-plugin-terser": "^7",
60
68
  "rollup-plugin-visualizer": "^5.5.4",
69
+ "sinon": "10.x.x",
61
70
  "ts-jest": "27.x.x",
62
71
  "ttypescript": "1.5.13",
63
72
  "typescript": "4.x.x",
@@ -65,5 +74,5 @@
65
74
  },
66
75
  "author": "",
67
76
  "license": "ISC",
68
- "gitHead": "2dc32e552dd5877be0ceb18f64cb896f13f15303"
77
+ "gitHead": "ffece352d3254302cfa09233b54d93dc73b839d5"
69
78
  }
package/test/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export {suite, test, timeout,} from "@testdeck/jest";
2
- export {expect,} from "@jest/globals";
2
+ export {expect,} from "@jest/globals";
3
+ export * as sinon from "sinon";
package/test/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export {suite, test, timeout,} from "@testdeck/jest";
2
2
  import * as globals from "@jest/globals";
3
-
3
+ import * as sinon1 from "sinon/pkg/sinon.js";
4
+ export const sinon = sinon1.default;
4
5
  const {expect} = globals;
5
6
  export {expect};