@enact/cli 4.1.7 → 5.0.0-alpha.1

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.
@@ -16,15 +16,17 @@ const fs = require('fs');
16
16
  const path = require('path');
17
17
  const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
18
18
  const ESLintPlugin = require('eslint-webpack-plugin');
19
- const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
19
+ const ForkTsCheckerWebpackPlugin =
20
+ process.env.TSC_COMPILE_ON_ERROR === 'true'
21
+ ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin')
22
+ : require('react-dev-utils/ForkTsCheckerWebpackPlugin');
20
23
  const HtmlWebpackPlugin = require('html-webpack-plugin');
21
24
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
22
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
25
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
23
26
  const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
24
27
  const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
25
28
  const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
26
- const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
27
- const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
29
+ const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
28
30
  const resolve = require('resolve');
29
31
  const TerserPlugin = require('terser-webpack-plugin');
30
32
  const {DefinePlugin, EnvironmentPlugin} = require('webpack');
@@ -35,10 +37,11 @@ const {
35
37
  ILibPlugin,
36
38
  WebOSMetaPlugin
37
39
  } = require('@enact/dev-utils');
40
+ const createEnvironmentHash = require('./createEnvironmentHash');
38
41
 
39
42
  // This is the production and development configuration.
40
43
  // It is focused on developer experience, fast rebuilds, and a minimal bundle.
41
- module.exports = function (env) {
44
+ module.exports = function (env, ilibAdditionalResourcesPath) {
42
45
  process.chdir(app.context);
43
46
 
44
47
  // Load applicable .env files into environment variables.
@@ -64,6 +67,9 @@ module.exports = function (env) {
64
67
  // Check if TypeScript is setup
65
68
  const useTypeScript = fs.existsSync('tsconfig.json');
66
69
 
70
+ // Check if Tailwind config exists
71
+ const useTailwind = fs.existsSync(path.join(app.context, 'tailwind.config.js'));
72
+
67
73
  process.env.NODE_ENV = env || process.env.NODE_ENV;
68
74
  const isEnvProduction = process.env.NODE_ENV === 'production';
69
75
 
@@ -97,15 +103,16 @@ module.exports = function (env) {
97
103
  options: Object.assign(
98
104
  {importLoaders: preProcessor ? 2 : 1, sourceMap: shouldUseSourceMap},
99
105
  cssLoaderOptions,
100
- cssLoaderOptions.modules && {modules: {getLocalIdent}},
101
106
  {
102
- url: url => {
103
- // Don't handle absolute path urls
104
- if (url.startsWith('/')) {
105
- return false;
106
- }
107
+ url: {
108
+ filter: url => {
109
+ // Don't handle absolute path urls
110
+ if (url.startsWith('/')) {
111
+ return false;
112
+ }
107
113
 
108
- return true;
114
+ return true;
115
+ }
109
116
  }
110
117
  }
111
118
  )
@@ -117,26 +124,33 @@ module.exports = function (env) {
117
124
  loader: require.resolve('postcss-loader'),
118
125
  options: {
119
126
  postcssOptions: {
127
+ // Necessary for external CSS imports to work
128
+ // https://github.com/facebook/create-react-app/issues/2677
129
+ ident: 'postcss',
120
130
  plugins: [
131
+ useTailwind && require('tailwindcss'),
121
132
  // Fix and adjust for known flexbox issues
122
133
  // See https://github.com/philipwalton/flexbugs
123
- require('postcss-flexbugs-fixes'),
134
+ 'postcss-flexbugs-fixes',
124
135
  // Support @global-import syntax to import css in a global context.
125
- require('postcss-global-import'),
136
+ 'postcss-global-import',
126
137
  // Transpile stage-3 CSS standards based on browserslist targets.
127
138
  // See https://preset-env.cssdb.org/features for supported features.
128
139
  // Includes support for targetted auto-prefixing.
129
- require('postcss-preset-env')({
130
- autoprefixer: {
131
- flexbox: 'no-2009',
132
- remove: false
133
- },
134
- stage: 3,
135
- features: {'custom-properties': false}
136
- }),
140
+ [
141
+ 'postcss-preset-env',
142
+ {
143
+ autoprefixer: {
144
+ flexbox: 'no-2009',
145
+ remove: false
146
+ },
147
+ stage: 3,
148
+ features: {'custom-properties': false}
149
+ }
150
+ ],
137
151
  // Adds PostCSS Normalize to standardize browser quirks based on
138
152
  // the browserslist targets.
139
- require('postcss-normalize')(),
153
+ !useTailwind && require('postcss-normalize'),
140
154
  // Resolution indepedence support
141
155
  app.ri !== false && require('postcss-resolution-independence')(app.ri)
142
156
  ].filter(Boolean)
@@ -191,6 +205,7 @@ module.exports = function (env) {
191
205
  filename: '[name].js',
192
206
  // There are also additional JS chunk files if you use code splitting.
193
207
  chunkFilename: 'chunk.[name].js',
208
+ assetModuleFilename: '[path][name][ext]',
194
209
  // Add /* filename */ comments to generated require()s in the output.
195
210
  pathinfo: !isEnvProduction,
196
211
  publicPath,
@@ -210,13 +225,21 @@ module.exports = function (env) {
210
225
  } else {
211
226
  return file;
212
227
  }
213
- },
214
- // Use webpack 5 handling of asset files; remove once upgraded to webpack 5
215
- futureEmitAssets: true,
216
- // Prevent potential conflicts in muliple runtimes
217
- jsonpFunction: 'webpackJsonp' + app.name,
218
- // Allow versatile 'global' mapping across multiple deploy formats
219
- globalObject: 'this'
228
+ }
229
+ },
230
+ cache: {
231
+ type: 'filesystem',
232
+ version: createEnvironmentHash(Object.keys(process.env)),
233
+ cacheDirectory: path.resolve('./node_modules/.cache'),
234
+ store: 'pack',
235
+ buildDependencies: {
236
+ defaultWebpack: ['webpack/lib/'],
237
+ config: [__filename],
238
+ tsconfig: useTypeScript ? ['tsconfig.json'] : []
239
+ }
240
+ },
241
+ infrastructureLogging: {
242
+ level: 'none'
220
243
  },
221
244
  resolve: {
222
245
  // These are the reasonable defaults supported by the React/ES6 ecosystem.
@@ -246,6 +269,12 @@ module.exports = function (env) {
246
269
  // @remove-on-eject-end
247
270
  module: {
248
271
  rules: [
272
+ shouldUseSourceMap && {
273
+ enforce: 'pre',
274
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
275
+ test: /\.(js|mjs|jsx|ts|tsx|css)$/,
276
+ loader: require.resolve('source-map-loader')
277
+ },
249
278
  {
250
279
  // "oneOf" will traverse all following loaders until one will
251
280
  // match the requirements. When no loader matches it will fall
@@ -273,13 +302,23 @@ module.exports = function (env) {
273
302
  // options used at each level of processing.
274
303
  {
275
304
  test: /\.module\.css$/,
276
- use: getStyleLoaders({modules: true})
305
+ use: getStyleLoaders({
306
+ modules: {
307
+ getLocalIdent,
308
+ mode: 'local'
309
+ }
310
+ })
277
311
  },
278
312
  {
279
313
  test: /\.css$/,
280
314
  // The `forceCSSModules` Enact build option can be set true to universally apply
281
315
  // modular CSS support.
282
- use: getStyleLoaders({modules: app.forceCSSModules}),
316
+ use: getStyleLoaders({
317
+ modules: {
318
+ ...(app.forceCSSModules ? {getLocalIdent} : {}),
319
+ mode: 'icss'
320
+ }
321
+ }),
283
322
  // Don't consider CSS imports dead code even if the
284
323
  // containing package claims to have no side effects.
285
324
  // Remove this when webpack adds a warning or an error for this.
@@ -288,18 +327,27 @@ module.exports = function (env) {
288
327
  },
289
328
  {
290
329
  test: /\.module\.less$/,
291
- use: getLessStyleLoaders({modules: true})
330
+ use: getLessStyleLoaders({
331
+ modules: {
332
+ getLocalIdent,
333
+ mode: 'local'
334
+ }
335
+ })
292
336
  },
293
337
  {
294
338
  test: /\.less$/,
295
- use: getLessStyleLoaders({modules: app.forceCSSModules}),
339
+ use: getLessStyleLoaders({
340
+ modules: {
341
+ ...(app.forceCSSModules ? {getLocalIdent} : {}),
342
+ mode: 'icss'
343
+ }
344
+ }),
296
345
  sideEffects: true
297
346
  },
298
347
  // "file" loader handles on all files not caught by the above loaders.
299
348
  // When you `import` an asset, you get its output filename and the file
300
349
  // is copied during the build process.
301
350
  {
302
- loader: require.resolve('file-loader'),
303
351
  // Exclude `js` files to keep "css" loader working as it injects
304
352
  // its runtime that would otherwise be processed through "file" loader.
305
353
  // Also exclude `html` and `json` extensions so they get processed
@@ -307,36 +355,21 @@ module.exports = function (env) {
307
355
  // Exclude `ejs` HTML templating language as that's handled by
308
356
  // the HtmlWebpackPlugin.
309
357
  exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.ejs$/, /\.json$/],
310
- options: {
311
- name: '[path][name].[ext]'
312
- }
358
+ type: 'asset/resource'
313
359
  }
314
360
  // ** STOP ** Are you adding a new loader?
315
361
  // Make sure to add the new loader(s) before the "file" loader.
316
362
  ]
317
363
  }
318
- ]
364
+ ].filter(Boolean)
319
365
  },
320
366
  // Specific webpack-dev-server options.
321
367
  devServer: {
322
368
  // Broadcast http server on the localhost, port 8080.
323
369
  host: '0.0.0.0',
324
- port: 8080,
325
- // Support the same public path as webpack config.
326
- publicPath: publicPath,
327
- // By default WebpackDevServer serves files from public and __mocks__ directories
328
- // in addition to all the virtual build products that it serves from memory.
329
- contentBase: [path.resolve('./public'), path.resolve('./__mocks__')],
330
- contentBasePublicPath: publicPath + '/',
331
- // Any changes to files from `contentBase` should trigger a page reload.
332
- watchContentBase: true,
333
- // Reportedly, this avoids CPU overload on some systems.
334
- // https://github.com/facebookincubator/create-react-app/issues/293
335
- watchOptions: {
336
- ignored: /node_modules[\\/](?!@enact[\\/](?!.*node_modules))/
337
- }
370
+ port: 8080
338
371
  },
339
- // Target app to build for a specific environment (default 'web')
372
+ // Target app to build for a specific environment (default 'browserslist')
340
373
  target: app.environment,
341
374
  // Optional configuration for polyfilling NodeJS built-ins.
342
375
  node: app.nodeBuiltins,
@@ -382,29 +415,9 @@ module.exports = function (env) {
382
415
  },
383
416
  // Use multi-process parallel running to improve the build speed
384
417
  // Default number of concurrent runs: os.cpus().length - 1
385
- parallel: true,
386
- // Enable file caching
387
- cache: true,
388
- sourceMap: shouldUseSourceMap
418
+ parallel: true
389
419
  }),
390
- new OptimizeCSSAssetsPlugin({
391
- cssProcessorOptions: {
392
- // TODO: verify calc issue fixed. Related: https://github.com/postcss/postcss-calc/issues/50
393
- // calc: false,
394
- parser: require('postcss-safe-parser'),
395
- map: shouldUseSourceMap && {
396
- // `inline: false` forces the sourcemap to be output into a
397
- // separate file
398
- inline: false,
399
- // `annotation: true` appends the sourceMappingURL to the end of
400
- // the css file, helping the browser find the sourcemap
401
- annotation: true
402
- }
403
- },
404
- cssProcessorPluginOptions: {
405
- preset: ['default', {minifyFontValues: {removeQuotes: false}}]
406
- }
407
- })
420
+ new CssMinimizerPlugin()
408
421
  ]
409
422
  },
410
423
  plugins: [
@@ -445,15 +458,12 @@ module.exports = function (env) {
445
458
  filename: '[name].css',
446
459
  chunkFilename: 'chunk.[name].css'
447
460
  }),
461
+ // Webpack5 removed node polyfills but we need this to run screenshot tests
462
+ new NodePolyfillPlugin(),
448
463
  // Provide meaningful information when modules are not found
449
464
  new ModuleNotFoundPlugin(app.context),
450
465
  // Ensure correct casing in module filepathes
451
466
  new CaseSensitivePathsPlugin(),
452
- // If you require a missing module and then `npm install` it, you still have
453
- // to restart the development server for Webpack to discover it. This plugin
454
- // makes the discovery automatic so you don't have to restart.
455
- // See https://github.com/facebookincubator/create-react-app/issues/186
456
- !isEnvProduction && new WatchMissingNodeModulesPlugin('./node_modules'),
457
467
  // Switch the internal NodeOutputFilesystem to use graceful-fs to avoid
458
468
  // EMFILE errors when hanndling mass amounts of files at once, such as
459
469
  // what happens when using ilib bundles/resources.
@@ -461,30 +471,52 @@ module.exports = function (env) {
461
471
  // Automatically configure iLib library within @enact/i18n. Additionally,
462
472
  // ensure the locale data files and the resource files are copied during
463
473
  // the build to the output directory.
464
- new ILibPlugin({symlinks: false}),
474
+ new ILibPlugin({publicPath, symlinks: false, ilibAdditionalResourcesPath}),
465
475
  // Automatically detect ./appinfo.json and ./webos-meta/appinfo.json files,
466
476
  // and parses any to copy over any webOS meta assets at build time.
467
477
  new WebOSMetaPlugin({htmlPlugin: HtmlWebpackPlugin}),
468
478
  // TypeScript type checking
469
479
  useTypeScript &&
470
480
  new ForkTsCheckerWebpackPlugin({
471
- typescript: resolve.sync('typescript', {
472
- basedir: 'node_modules'
473
- }),
474
481
  async: !isEnvProduction,
475
- checkSyntacticErrors: true,
476
- tsconfig: 'tsconfig.json',
477
- reportFiles: [
478
- '../**/src/**/*.{ts,tsx}',
479
- '**/src/**/*.{ts,tsx}',
480
- '!**/src/**/__tests__/**',
481
- '!**/src/**/?(*.)+(spec|test).*',
482
- '!**/src/setupProxy.*',
483
- '!**/src/setupTests.*'
484
- ],
485
- silent: true,
486
- // The formatter is invoked directly in WebpackDevServerUtils during development
487
- formatter: !process.env.DISABLE_TSFORMATTER ? typescriptFormatter : undefined
482
+ typescript: {
483
+ typescriptPath: resolve.sync('typescript', {
484
+ basedir: 'node_modules'
485
+ }),
486
+ configOverwrite: {
487
+ compilerOptions: {
488
+ sourceMap: shouldUseSourceMap,
489
+ skipLibCheck: true,
490
+ inlineSourceMap: false,
491
+ declarationMap: false,
492
+ noEmit: true,
493
+ incremental: true,
494
+ tsBuildInfoFile: 'node_modules/.cache/tsconfig.tsbuildinfo'
495
+ }
496
+ },
497
+ context: app.context,
498
+ diagnosticOptions: {
499
+ syntactic: true
500
+ },
501
+ mode: 'write-references'
502
+ // profile: true,
503
+ },
504
+ issue: {
505
+ // prettier-ignore
506
+ include: [
507
+ {file: '../**/src/**/*.{ts,tsx}'},
508
+ {file: '**/src/**/*.{ts,tsx}'}
509
+ ],
510
+ exclude: [
511
+ {file: '**/src/**/__tests__/**'},
512
+ {file: '**/src/**/?(*.){spec|test}.*'},
513
+ {file: '**/src/setupProxy.*'},
514
+ {file: '**/src/setupTests.*'}
515
+ ]
516
+ },
517
+ logger: {
518
+ infrastructure: 'silent'
519
+ }
488
520
  }),
489
521
  new ESLintPlugin({
490
522
  // Plugin options