@cmmn/tools 2.0.1 → 2.0.2

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.
@@ -104,10 +104,10 @@ export class ConfigCreator {
104
104
  return this.options.module.split(',');
105
105
  }
106
106
  getOutExtension(format, platform){
107
- const ext = (this.options.minify ? '.min' : '') + {
107
+ const ext = (this.options.minify ? '.min' : '') + ({
108
108
  es: '.js',
109
109
  cjs: '.cjs'
110
- }[format];
110
+ }[format] ?? '.js');
111
111
  if (this.platforms.length == 1)
112
112
  return ext;
113
113
  return "."+platform+ext;
@@ -124,13 +124,13 @@ export class ConfigCreator {
124
124
  { out: this.options.name, in: this.options.input }
125
125
  ],
126
126
  bundle: true,
127
- minify: this.options.minify || this.options.prod,
127
+ minify: this.options.minify,
128
128
  sourcemap: this.options.prod ? false : 'external',
129
129
  target: ['chrome88', 'safari14', 'firefox88'],
130
130
  outdir: 'dist/bundle',
131
131
  metafile: true,
132
132
  absWorkingDir: this.root,
133
- treeShaking: this.options.minify,
133
+ treeShaking: this.options.prod,
134
134
  format: ({
135
135
  es: 'esm'
136
136
  })[format] ?? format,
@@ -156,6 +156,21 @@ export class ConfigCreator {
156
156
  plugins: [
157
157
  lessLoader(),
158
158
  ...this.getHtmlPlugin(),
159
+ {
160
+ name: 'no-side-effects',
161
+ setup(build){
162
+ build.onResolve({ filter: /.*/ }, async args => {
163
+ if (args.pluginData) return // Ignore this if we called ourselves
164
+
165
+ const { path, ...rest } = args
166
+ rest.pluginData = true // Avoid infinite recursion
167
+ const result = await build.resolve(path, rest)
168
+
169
+ result.sideEffects = false
170
+ return result
171
+ })
172
+ }
173
+ }
159
174
  ],
160
175
  })));
161
176
  }
@@ -80,12 +80,12 @@ class Visitor {
80
80
  const outFile = path.resolve(absSource, importPath).replaceAll(path.sep, '/') + '.js';
81
81
  fs.mkdirSync(path.dirname(outFile), {recursive: true});
82
82
  fs.writeFileSync(outFile, 'export default `'+content.replaceAll('`','\\`')+'`', 'utf-8');
83
- return importPath+".js";
83
+ return importPath.replaceAll(path.sep, '/') + ".js";
84
84
  }
85
85
  if (this.config.copy.test(importPath)) {
86
- return path.relative(absSource,abs);
86
+ return path.relative(absSource,abs).replaceAll(path.sep, '/');
87
87
  }
88
- return importPath;
88
+ return importPath.replaceAll(path.sep, '/');
89
89
  }
90
90
 
91
91
  visitSourceFile = sourceFile => ts.visitEachChild(sourceFile, node => this.visit(node,sourceFile), this.context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",