chisel-scripts 1.0.0-alpha.4 → 1.0.0-alpha.8

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/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  <!-- INSERT-NEW-ENTRIES-HERE -->
4
4
 
5
+ ## 1.0.0-alpha.8 (2021-12-16)
6
+
7
+ ## 1.0.0-alpha.7 (2020-09-21)
8
+
9
+ - Add WP dev server test with puppeteer ([dbc0f1d](https://github.com/xfiveco/generator-chisel/commit/dbc0f1d))
10
+
11
+ ## 1.0.0-alpha.6 (2020-08-06)
12
+
13
+ - Update CSS bundling: use custom loader instead of importer, make fibers optional ([829dc26](https://github.com/xfiveco/generator-chisel/commit/829dc26))
14
+
15
+ ## 1.0.0-alpha.5 (2020-08-04)
16
+
17
+ - Add frontend generator and commands tests ([c32fa26](https://github.com/xfiveco/generator-chisel/commit/c32fa26))
18
+ - Fix source maps for styles during development ([8ba6e78](https://github.com/xfiveco/generator-chisel/commit/8ba6e78))
19
+ - Improve base config, final config generation ([61ce1d5](https://github.com/xfiveco/generator-chisel/commit/61ce1d5))
20
+ - Update babel loader config: support transpileDependencies, exclude assets ([c5e21bd](https://github.com/xfiveco/generator-chisel/commit/c5e21bd))
21
+
5
22
  ## 1.0.0-alpha.4 (2020-07-21)
6
23
 
7
24
  - Add Changelogs ([25d6245](https://github.com/xfiveco/generator-chisel/commit/25d6245))
@@ -2,9 +2,26 @@
2
2
 
3
3
  const Service = require('../lib/Service');
4
4
 
5
- const service = new Service();
5
+ // console.log('CREATE SERVICE');
6
6
 
7
- service.run(process.argv[2], process.argv.slice(3)).catch((err) => {
8
- console.error(err);
9
- process.exit(1);
10
- });
7
+ if (!Object.fromEntries) {
8
+ Object.fromEntries = function fromEntries(iterable) {
9
+ return [...iterable].reduce((obj, [key, val]) => {
10
+ obj[key] = val;
11
+ return obj;
12
+ }, {});
13
+ };
14
+ }
15
+
16
+ if (typeof jest !== 'undefined') {
17
+ module.exports = (argv) => {
18
+ const service = new Service();
19
+ return service.run(argv[0], argv.slice(1));
20
+ };
21
+ } else {
22
+ const service = new Service();
23
+ service.run(process.argv[2], process.argv.slice(3)).catch((err) => {
24
+ console.error(err);
25
+ process.exit(1);
26
+ });
27
+ }
package/lib/Service.js CHANGED
@@ -182,7 +182,17 @@ module.exports = class Service {
182
182
 
183
183
  const commanderArgs = [...(name ? [name] : []), ...args];
184
184
 
185
- return this.program.parseAsync(commanderArgs, { from: 'user' });
185
+ await this.program.parseAsync(commanderArgs, { from: 'user' });
186
+ if (this.program._actionResults) {
187
+ const results = await Promise.all(this.program._actionResults);
188
+ if (results.length === 1) {
189
+ return results[0];
190
+ }
191
+
192
+ return results;
193
+ }
194
+
195
+ return undefined;
186
196
  }
187
197
 
188
198
  async resolveChainableWebpackConfig() {
@@ -202,7 +212,14 @@ module.exports = class Service {
202
212
  let config = chainableConfig.toConfig();
203
213
  const original = config;
204
214
 
205
- config.node = false;
215
+ if (typeof config.node === 'undefined') {
216
+ config.node = false;
217
+ }
218
+
219
+ if (!Array.isArray(config.externals)) {
220
+ config.externals =
221
+ typeof config.externals === 'undefined' ? [] : [config.externals];
222
+ }
206
223
 
207
224
  // apply raw config fns
208
225
  this.webpackRawConfigFns.forEach((fn) => {
@@ -16,10 +16,14 @@ module.exports = {
16
16
  assets: 'assets',
17
17
  },
18
18
 
19
+ wp: {
20
+ directoryName: 'wp',
21
+ },
22
+
19
23
  staticFrontend: {
20
24
  serveDist: false,
21
25
  skipHtmlExtension: false,
22
- buildFormat: 'prettify', // pretty, minify, as-is/undefined
26
+ buildFormat: 'prettify', // prettify, minify, as-is/undefined
23
27
  htmlHint: true,
24
28
  },
25
29
 
@@ -19,7 +19,37 @@ module.exports = (api, options) => {
19
19
  webpackConfig.optimization.minimize(false);
20
20
  }
21
21
  } else {
22
- webpackConfig.mode('development').devtool('cheap-module-eval-source-map');
22
+ // webpackConfig.mode('development').devtool('cheap-module-eval-source-map');
23
+ webpackConfig.mode('development').devtool(false);
24
+
25
+ // Use separate source maps for styles due to
26
+ // https://github.com/webpack-contrib/mini-css-extract-plugin/issues/529
27
+
28
+ const devToolShared = {
29
+ module: true,
30
+ columns: false,
31
+ noSources: false,
32
+ };
33
+
34
+ // * is mini-css-extract-plugin
35
+
36
+ webpackConfig
37
+ .plugin('devtool-default')
38
+ .use(require('webpack/lib/EvalSourceMapDevToolPlugin'), [
39
+ {
40
+ ...devToolShared,
41
+ test: /(?!(?:^\*|\.s?css)$)/,
42
+ },
43
+ ]);
44
+
45
+ webpackConfig
46
+ .plugin('devtool-styles')
47
+ .use(require('webpack/lib/SourceMapDevToolPlugin'), [
48
+ {
49
+ ...devToolShared,
50
+ test: /(?=(?:^\*|\.s?css)$)/,
51
+ },
52
+ ]);
23
53
  }
24
54
 
25
55
  const baseDir = api.resolve(options.source.base);
package/lib/config/css.js CHANGED
@@ -1,6 +1,5 @@
1
1
  module.exports = (api, options) => {
2
2
  api.chainWebpack((webpackConfig) => {
3
- const globby = require('globby');
4
3
  const path = require('path');
5
4
 
6
5
  const isProd = process.env.NODE_ENV === 'production';
@@ -11,21 +10,7 @@ module.exports = (api, options) => {
11
10
  sassOptions: {
12
11
  indentedSyntax: false,
13
12
  includePaths: [api.resolve('node_modules')], // TODO: don't use?
14
- outputStyle: 'expanded', // TODO: test postcss and add minifier
15
- importer(url, prev, done) {
16
- (async () => {
17
- if (globby.hasMagic(url)) {
18
- const files = (
19
- await globby(url, { cwd: path.dirname(prev) })
20
- ).sort();
21
- done({
22
- contents: files.map((file) => `@import '${file}';`).join('\n'),
23
- });
24
- } else {
25
- done(null);
26
- }
27
- })();
28
- },
13
+ outputStyle: 'expanded',
29
14
  },
30
15
  };
31
16
 
@@ -50,6 +35,9 @@ module.exports = (api, options) => {
50
35
  path.join(options.source.base, options.source.assets),
51
36
  );
52
37
 
38
+ // Note: thread loader cannot be used right now
39
+ // https://github.com/webpack-contrib/thread-loader/issues/79
40
+
53
41
  const createCssLoader = (rule, test) => {
54
42
  // prettier-ignore
55
43
  return webpackConfig.module.rule(rule).test(test)
@@ -78,6 +66,9 @@ module.exports = (api, options) => {
78
66
  .loader(require.resolve('sass-loader'))
79
67
  .options(sassLoaderOptions)
80
68
  .end()
69
+ .use('sass-glob-loader')
70
+ .loader(require.resolve('../webpack-loaders/sass-glob-loader.js'))
71
+ .end();
81
72
 
82
73
  webpackConfig
83
74
  .plugin('extract-css')
package/lib/config/js.js CHANGED
@@ -1,10 +1,47 @@
1
1
  // TODO: allow easy inclusion of selected node modules
2
2
  // cache loader?
3
3
 
4
- module.exports = (api) => {
4
+ const path = require('path');
5
+
6
+ const isWindows = process.platform === 'win32';
7
+ // https://github.com/vuejs/vue-cli/blob/544e0547054947c471fe9d71a2b967e57f5f3111/packages/%40vue/cli-plugin-babel/index.js
8
+ function genTranspileDepRegex(transpileDependencies) {
9
+ const deps = transpileDependencies.map((dep) => {
10
+ if (typeof dep === 'string') {
11
+ const depPath = path.join('node_modules', dep, '/');
12
+ return isWindows
13
+ ? depPath.replace(/\\/g, '\\\\') // double escape for windows style path
14
+ : depPath;
15
+ }
16
+ if (dep instanceof RegExp) {
17
+ return dep.source;
18
+ }
19
+ return undefined;
20
+ });
21
+ return deps.length ? new RegExp(deps.join('|')) : null;
22
+ }
23
+
24
+ module.exports = (api, options) => {
5
25
  api.chainWebpack((webpackConfig) => {
26
+ const transpileDepRegex = genTranspileDepRegex(
27
+ options.transpileDependencies || [],
28
+ );
29
+
30
+ const excludeFunction = (filepath) => {
31
+ if (transpileDepRegex && transpileDepRegex.test(filepath)) {
32
+ return false;
33
+ }
34
+ // Don't transpile node_modules
35
+ return /node_modules/.test(filepath);
36
+ };
37
+
6
38
  // prettier-ignore
7
- webpackConfig.module.rule('js').test(/\.m?jsx?$/).exclude.add(/node_modules/).end()
39
+ webpackConfig.module.rule('js')
40
+ .test(/\.m?jsx?$/)
41
+ .exclude
42
+ .add(excludeFunction)
43
+ .add(api.resolve(options.source.base, options.source.assets))
44
+ .end()
8
45
  .use('babel-loader')
9
46
  .loader(require.resolve('babel-loader'))
10
47
 
@@ -0,0 +1,41 @@
1
+ // Based on https://github.com/mikevercoelen/gulp-sass-glob/blob/255ee047789e69c82d5e3fc87452360ef8c56f41/src/index.js
2
+
3
+ // we initially used custom dart-sass importer instead of this but there
4
+ // is noticeable performance difference
5
+
6
+ const path = require('path');
7
+ const globby = require('globby');
8
+
9
+ const IMPORT_RE = /^([ \t]*(?:\/\*.*)?)@import\s+["']([^"']+(?:\.scss|\.sass)?)["'];?([ \t]*(?:\/[/*].*)?)$/gm;
10
+
11
+ module.exports = async function sassGlobLoader(content) {
12
+ // console.log(`Sass glob loader for ${this.resourcePath}`);
13
+
14
+ const file = this.resourcePath;
15
+ const base = path.dirname(file);
16
+
17
+ const newContent = content.replace(
18
+ IMPORT_RE,
19
+ (importRule, startComment, globPattern, endComment) => {
20
+ if (globby.hasMagic(globPattern)) {
21
+ const files = globby.sync(globPattern, { cwd: base }).sort();
22
+
23
+ const filesString = files.map((f) => `@import '${f}';`).join('\n');
24
+
25
+ // Inlining sources here makes sass build even faster
26
+ // but breaks source maps
27
+ // const filesString = files
28
+ // .map((f) => fs.readFileSync(path.join(base, f), 'utf8'))
29
+ // .join('\n');
30
+
31
+ return startComment + filesString + endComment;
32
+ }
33
+
34
+ return importRule;
35
+ },
36
+ );
37
+
38
+ // console.log(newContent);
39
+
40
+ return newContent;
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chisel-scripts",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.8",
4
4
  "description": "TODO",
5
5
  "bin": {
6
6
  "chisel-scripts": "bin/chisel-scripts.js"
@@ -36,7 +36,6 @@
36
36
  "commander": "^5.1.0",
37
37
  "css-loader": "^3.5.3",
38
38
  "cssnano": "^4.1.10",
39
- "fibers": "^5.0.0",
40
39
  "file-loader": "^6.0.0",
41
40
  "fs-extra": "^9.0.1",
42
41
  "globby": "^11.0.1",
@@ -61,5 +60,8 @@
61
60
  "webpack-merge": "^4.2.2",
62
61
  "webpackbar": "^4.0.0"
63
62
  },
64
- "gitHead": "bfa44f894a295b562f472e4c6899eb2ba59d2f02"
63
+ "optionalDependencies": {
64
+ "fibers": "^5.0.0"
65
+ },
66
+ "gitHead": "a4f0deade67a28ccf68ce08ab89b32c15b3d9864"
65
67
  }