gdu 4.0.0-next.13 → 4.0.0-next.17

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
@@ -1,5 +1,29 @@
1
1
  # gdu
2
2
 
3
+ ## 4.0.0-next.17
4
+
5
+ ### Patch Changes
6
+
7
+ - GDU: Improves build maniset plugin
8
+
9
+ ## 4.0.0-next.16
10
+
11
+ ### Patch Changes
12
+
13
+ - GDU: Fixes build manifest plugin
14
+
15
+ ## 4.0.0-next.15
16
+
17
+ ### Patch Changes
18
+
19
+ - GDU Assumed prod env fro build commands
20
+
21
+ ## 4.0.0-next.14
22
+
23
+ ### Patch Changes
24
+
25
+ - GDU: Exposes naked nextjs configs
26
+
3
27
  ## 4.0.0-next.13
4
28
 
5
29
  ### Patch Changes
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildSSR = void 0;
7
7
  const path_1 = require("path");
8
8
  const utilities_1 = require("@autoguru/utilities");
9
- const roots_1 = require("../../lib/roots");
10
9
  const execa_1 = __importDefault(require("execa"));
11
10
  const kleur_1 = require("kleur");
11
+ const roots_1 = require("../../lib/roots");
12
12
  const logger = utilities_1.createLogger('build');
13
13
  const buildSSR = async (guruConfig) => {
14
14
  const start = Date.now();
@@ -1 +1,14 @@
1
- export declare const createNextJSConfig: () => {};
1
+ export declare const withTM: (nextConfig?: {}) => {};
2
+ export declare const createNextJSConfig: () => {
3
+ reactStrictMode: boolean;
4
+ experimental: {
5
+ esmExternals: boolean;
6
+ externalDir: boolean;
7
+ };
8
+ images: {
9
+ domains: string[];
10
+ formats: string[];
11
+ };
12
+ webpack: (defaultConfig: any) => any;
13
+ };
14
+ export declare const createNextJSTranspiledConfig: () => any;
@@ -22,17 +22,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.createNextJSConfig = void 0;
26
- const roots_1 = require("../lib/roots");
25
+ exports.createNextJSTranspiledConfig = exports.createNextJSConfig = exports.withTM = void 0;
27
26
  const path_1 = __importStar(require("path"));
28
- const webpack_1 = require("webpack");
29
- const misc_1 = require("../lib/misc");
27
+ const next_plugin_1 = require("@vanilla-extract/next-plugin");
30
28
  const dotenv_webpack_1 = __importDefault(require("dotenv-webpack"));
31
29
  const next_transpile_modules_1 = __importDefault(require("next-transpile-modules"));
30
+ const webpack_1 = require("webpack");
31
+ const misc_1 = require("../lib/misc");
32
+ const roots_1 = require("../lib/roots");
32
33
  const configs_1 = require("../utils/configs");
33
- const webpack_plugin_1 = require("@vanilla-extract/webpack-plugin");
34
- const loaders_1 = require("next/dist/build/webpack/config/blocks/css/loaders");
35
- const withTM = next_transpile_modules_1.default([
34
+ const withVanillaExtract = next_plugin_1.createVanillaExtractPlugin();
35
+ exports.withTM = next_transpile_modules_1.default([
36
36
  '@autoguru/themes',
37
37
  '@autoguru/overdrive',
38
38
  '@autoguru/icons',
@@ -46,7 +46,7 @@ const withTM = next_transpile_modules_1.default([
46
46
  ]);
47
47
  const createNextJSConfig = () => {
48
48
  const isDev = !misc_1.isEnvProduction();
49
- return withTM({
49
+ return {
50
50
  reactStrictMode: true,
51
51
  experimental: {
52
52
  esmExternals: false,
@@ -54,25 +54,9 @@ const createNextJSConfig = () => {
54
54
  },
55
55
  images: {
56
56
  domains: ['cdn.autoguru.com.au'],
57
+ formats: ['image/webp'],
57
58
  },
58
- webpack: (defaultConfig, options) => {
59
- const { dev, isServer } = options;
60
- const cssRules = defaultConfig.module.rules.find((rule) => Array.isArray(rule.oneOf) &&
61
- rule.oneOf.some(({ test }) => typeof test === 'object' &&
62
- typeof test.test === 'function' &&
63
- test.test('filename.css'))).oneOf;
64
- cssRules.unshift({
65
- test: /\.vanilla\.css$/i,
66
- sideEffects: true,
67
- use: loaders_1.getGlobalCssLoader({
68
- assetPrefix: defaultConfig.assetPrefix,
69
- isClient: !isServer,
70
- isServer,
71
- isDevelopment: dev,
72
- future: defaultConfig.future || {},
73
- experimental: defaultConfig.experimental || {},
74
- }, [], []),
75
- });
59
+ webpack: (defaultConfig) => {
76
60
  defaultConfig.plugins.push(new webpack_1.DefinePlugin({
77
61
  __DEV__: isDev,
78
62
  }));
@@ -82,7 +66,9 @@ const createNextJSConfig = () => {
82
66
  path: path_1.default.resolve(configsDir, '.env.defaults'),
83
67
  }),
84
68
  new dotenv_webpack_1.default({
85
- path: path_1.default.resolve(configsDir, `.env.${process.env.APP_ENV || 'dev'}`),
69
+ path: path_1.default.resolve(configsDir, `.env.${process.env.APP_ENV || misc_1.isEnvProduction()
70
+ ? 'prod'
71
+ : 'dev'}`),
86
72
  }),
87
73
  ])
88
74
  .forEach((plugin) => defaultConfig.plugins.push(plugin));
@@ -90,9 +76,10 @@ const createNextJSConfig = () => {
90
76
  defaultConfig.resolve.alias['react-dom'] = path_1.resolve(roots_1.PROJECT_ROOT, '../../', 'node_modules/react-dom/');
91
77
  defaultConfig.resolve.alias['@autoguru/icons'] = path_1.resolve(roots_1.PROJECT_ROOT, '../../', 'node_modules/@autoguru/icons/');
92
78
  defaultConfig.resolve.alias['next'] = path_1.resolve(roots_1.PROJECT_ROOT, '../../', 'node_modules/next/');
93
- defaultConfig.plugins.push(new webpack_plugin_1.VanillaExtractPlugin());
94
79
  return defaultConfig;
95
80
  },
96
- });
81
+ };
97
82
  };
98
83
  exports.createNextJSConfig = createNextJSConfig;
84
+ const createNextJSTranspiledConfig = () => withVanillaExtract(exports.withTM(exports.createNextJSConfig()));
85
+ exports.createNextJSTranspiledConfig = createNextJSTranspiledConfig;
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.run = void 0;
7
7
  const utilities_1 = require("@autoguru/utilities");
8
- const roots_1 = require("../../lib/roots");
9
8
  const execa_1 = __importDefault(require("execa"));
10
9
  const kleur_1 = require("kleur");
11
10
  const misc_1 = require("../../lib/misc");
11
+ const roots_1 = require("../../lib/roots");
12
12
  const logger = utilities_1.createLogger('server');
13
13
  const run = async (port) => {
14
14
  const start = Date.now();
@@ -1,4 +1,21 @@
1
1
  import { Compiler } from 'webpack';
2
+ declare const defaultOptions: {
3
+ excludeFile: RegExp;
4
+ chunkGroupName: (filename: any) => string;
5
+ outputDir: string;
6
+ filename: string;
7
+ objectToString: (result: any) => string;
8
+ includeChunks: boolean;
9
+ publicPath: string;
10
+ };
2
11
  export declare class GuruBuildManifest {
12
+ private options;
13
+ private result;
14
+ constructor(options: Partial<typeof defaultOptions>);
3
15
  apply(compiler: Compiler): void;
16
+ saveJson(): void;
17
+ _excludeChunk(excludeCriterium: any, filename: any, chunk: any): any;
18
+ _shouldFolderBeCreated(outputDir: any): any;
19
+ _normalizeOutputDir(outputDir: any): any;
4
20
  }
21
+ export {};
@@ -1,55 +1,103 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.GuruBuildManifest = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = require("path");
9
+ const emptyResults = {
10
+ hash: '',
11
+ assets: {
12
+ js: [],
13
+ css: [],
14
+ },
15
+ chunks: {
16
+ js: [],
17
+ css: [],
18
+ },
19
+ };
20
+ const pluginName = 'GuruBuildManifestPlugin';
21
+ const defaultOptions = {
22
+ excludeFile: /\.hot-update\.js$/,
23
+ chunkGroupName: (filename) => /\.([\da-z]+(\.map)?)(\?.*)?$/.exec(filename)[1],
24
+ outputDir: process.cwd(),
25
+ filename: 'build-manifest.json',
26
+ objectToString: (result) => JSON.stringify(result),
27
+ includeChunks: true,
28
+ publicPath: '',
29
+ };
4
30
  class GuruBuildManifest {
5
- apply(compiler) {
6
- const fileMap = {
7
- hash: '',
8
- env: {},
31
+ constructor(options) {
32
+ this.options = {};
33
+ this.result = emptyResults;
34
+ this.options = Object.assign({}, defaultOptions, options);
35
+ this.result = {
36
+ ...emptyResults,
9
37
  };
10
- const configChunks = new Map();
11
- compiler.hooks.make.tap('BuildManifestPlugin', (compilation) => {
38
+ }
39
+ apply(compiler) {
40
+ compiler.hooks.emit.tap(pluginName, (compilation) => {
41
+ this.result = { ...emptyResults };
42
+ this.result.hash = compilation.hash;
43
+ compilation.chunks.forEach((chunk) => {
44
+ chunk.files.forEach((filename) => {
45
+ if (this._excludeChunk(this.options.excludeFile, filename, chunk) === true) {
46
+ return;
47
+ }
48
+ const ext = this.options.chunkGroupName(filename, chunk);
49
+ if (chunk.name)
50
+ this.result.assets[ext].push(`${this.options.publicPath}${filename}`);
51
+ else if (this.options.includeChunks)
52
+ this.result.chunks[ext].push(`${this.options.publicPath}${filename}`);
53
+ });
54
+ });
55
+ if (!this.options.includeChunks)
56
+ this.result.chunks = void 0;
57
+ this.saveJson();
12
58
  });
13
- compiler.hooks.emit.tapAsync('BuildManifestPlugin', (compilation, cb) => {
14
- fileMap.hash = compilation.hash;
15
- const js = [];
16
- const css = [];
17
- for (const [, entrypoint,] of compilation.entrypoints.entries()) {
18
- for (const file of entrypoint.getFiles()) {
19
- if (file.endsWith('.js'))
20
- js.push(file);
21
- if (file.endsWith('.css'))
22
- css.push(file);
59
+ }
60
+ saveJson() {
61
+ if (this._shouldFolderBeCreated(this.options.outputDir) === true) {
62
+ let pathStep = process.cwd();
63
+ const normalizedOutputPath = this._normalizeOutputDir(this.options.outputDir);
64
+ normalizedOutputPath.split('/').forEach((folder) => {
65
+ pathStep = path_1.join(pathStep, folder);
66
+ try {
67
+ fs_1.default.mkdirSync(pathStep);
23
68
  }
24
- }
25
- for (const [name, { chunk, config },] of configChunks.entries()) {
26
- const prefixCreator = (path) => {
27
- var _a, _b, _c;
28
- return `${(_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.publicPathBase) !== null && _b !== void 0 ? _b : ''}${(_c = compiler.options.output.publicPath) !== null && _c !== void 0 ? _c : ''}${path}`;
29
- };
30
- fileMap.env[name] = {
31
- js: [
32
- ...chunk.files.filter((i) => i.endsWith('.js')),
33
- ...js,
34
- ].map((i) => prefixCreator(i)),
35
- css: [...css].map((i) => prefixCreator(i)),
36
- };
37
- }
38
- compilation.assets['build-manifest.json'] = makeSource(JSON.stringify(fileMap, null, 4));
39
- cb();
40
- });
69
+ catch {
70
+ }
71
+ });
72
+ }
73
+ const file = path_1.resolve(this.options.outputDir, this.options.filename);
74
+ const blob = this.options.objectToString(this.result);
75
+ try {
76
+ fs_1.default.writeFileSync(file, blob, { flag: 'w' });
77
+ console.log(`File successfully created - ${file}`);
78
+ }
79
+ catch (error) {
80
+ console.error(error);
81
+ }
82
+ }
83
+ _excludeChunk(excludeCriterium, filename, chunk) {
84
+ if (typeof excludeCriterium === 'function') {
85
+ return excludeCriterium(filename, chunk);
86
+ }
87
+ if (excludeCriterium instanceof RegExp) {
88
+ return excludeCriterium.test(filename);
89
+ }
90
+ return true;
91
+ }
92
+ _shouldFolderBeCreated(outputDir) {
93
+ const isAbsolutePathWithProjectRoot = outputDir.includes(process.cwd());
94
+ const isPathWithinProjectRoot = !outputDir.startsWith('/');
95
+ return (isAbsolutePathWithProjectRoot || isPathWithinProjectRoot || false);
96
+ }
97
+ _normalizeOutputDir(outputDir) {
98
+ const removedRelativePrefix = outputDir.replace(/^\.\//, '');
99
+ const removeAbsolutePrefix = removedRelativePrefix.replace(process.cwd(), '');
100
+ return removeAbsolutePrefix;
41
101
  }
42
102
  }
43
103
  exports.GuruBuildManifest = GuruBuildManifest;
44
- const makeSource = (contents) => ({
45
- source() {
46
- return Buffer.from(contents);
47
- },
48
- size() {
49
- return Buffer.byteLength(contents);
50
- },
51
- updateHash: null,
52
- map: null,
53
- sourceAndMap: null,
54
- buffer: null,
55
- });
@@ -23,23 +23,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const path_1 = __importStar(require("path"));
26
+ const webpack_plugin_1 = require("@vanilla-extract/webpack-plugin");
26
27
  const browserslist_config_autoguru_1 = __importDefault(require("browserslist-config-autoguru"));
27
28
  const clean_webpack_plugin_1 = require("clean-webpack-plugin");
28
29
  const dotenv_webpack_1 = __importDefault(require("dotenv-webpack"));
30
+ const env_ci_1 = __importDefault(require("env-ci"));
29
31
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
30
32
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
31
- const webpack_plugin_1 = require("treat/webpack-plugin");
32
- const webpack_plugin_2 = require("@vanilla-extract/webpack-plugin");
33
+ const webpack_plugin_2 = require("treat/webpack-plugin");
33
34
  const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
34
35
  const webpack_1 = require("webpack");
35
36
  const config_1 = require("../../lib/config");
36
37
  const misc_1 = require("../../lib/misc");
37
38
  const roots_1 = require("../../lib/roots");
39
+ const configs_1 = require("../../utils/configs");
38
40
  const hooks_1 = require("../../utils/hooks");
39
41
  const common_1 = require("./blocks/common");
40
42
  const GuruBuildManifest_1 = require("./plugins/GuruBuildManifest");
41
- const configs_1 = require("../../utils/configs");
42
- const env_ci_1 = __importDefault(require("env-ci"));
43
43
  const { branch = 'null', commit = 'null' } = env_ci_1.default();
44
44
  const terserOptions = {
45
45
  ie8: false,
@@ -72,7 +72,7 @@ const ourCodePaths = [
72
72
  /@autoguru[/\\]/,
73
73
  ].filter(Boolean);
74
74
  const fileMask = isDev ? '[name]' : '[name]-[contenthash:8]';
75
- const baseOptions = {
75
+ const baseOptions = (buildEnv) => ({
76
76
  context: roots_1.PROJECT_ROOT,
77
77
  mode: isDev ? 'development' : 'production',
78
78
  entry: {
@@ -82,6 +82,9 @@ const baseOptions = {
82
82
  path_1.join(gduEntryPath, '/spa/client.js'),
83
83
  ].filter(Boolean),
84
84
  },
85
+ experiments: {
86
+ layers: true,
87
+ },
85
88
  cache: {
86
89
  type: 'filesystem',
87
90
  cacheLocation: path_1.resolve(roots_1.PROJECT_ROOT, '.build_cache'),
@@ -91,7 +94,6 @@ const baseOptions = {
91
94
  },
92
95
  },
93
96
  devtool: isDev ? 'eval-cheap-module-source-map' : 'source-map',
94
- bail: !isDev || !process.env.APP_ENV,
95
97
  resolve: {
96
98
  extensions: ['.tsx', '.ts', '.mjs', '.jsx', '.js', '.json'],
97
99
  plugins: [
@@ -259,7 +261,7 @@ const baseOptions = {
259
261
  branch,
260
262
  }),
261
263
  }),
262
- new webpack_plugin_1.TreatPlugin({
264
+ new webpack_plugin_2.TreatPlugin({
263
265
  outputLoaders: [
264
266
  {
265
267
  loader: misc_1.isEnvProduction()
@@ -270,23 +272,29 @@ const baseOptions = {
270
272
  minify: !isDev,
271
273
  browsers: browserslist_config_autoguru_1.default,
272
274
  }),
273
- new webpack_plugin_2.VanillaExtractPlugin(),
275
+ new webpack_plugin_1.VanillaExtractPlugin(),
274
276
  new mini_css_extract_plugin_1.default({
275
277
  filename: `${fileMask}.css`,
276
278
  chunkFilename: `chunks/${fileMask}.css`,
277
279
  ignoreOrder: true,
278
280
  }),
279
- !isDev && new GuruBuildManifest_1.GuruBuildManifest(),
280
281
  ...configs_1.getConfigsDirs().flatMap((configsDir) => [
281
282
  new dotenv_webpack_1.default({
282
283
  path: path_1.default.resolve(configsDir, '.env.defaults'),
283
284
  }),
284
285
  new dotenv_webpack_1.default({
285
- path: path_1.default.resolve(configsDir, `.env.${process.env.APP_ENV || 'dev'}`),
286
+ path: path_1.default.resolve(configsDir, `.env.${process.env.APP_ENV || (isDev ? 'dev' : buildEnv)}`),
286
287
  }),
287
288
  ]),
289
+ !isDev &&
290
+ new GuruBuildManifest_1.GuruBuildManifest({
291
+ outputDir: buildEnv === 'prod'
292
+ ? path_1.resolve(roots_1.PROJECT_ROOT, 'dist')
293
+ : path_1.resolve(roots_1.PROJECT_ROOT, 'dist', buildEnv),
294
+ includeChunks: false,
295
+ }),
288
296
  ].filter(Boolean),
289
- };
297
+ });
290
298
  const buildEnvs = process.env.APP_ENV
291
299
  ? [process.env.APP_ENV]
292
300
  : ['dev', 'uat', 'test', 'preprod', 'prod'];
@@ -296,7 +304,7 @@ const makeWebpackConfig = (buildEnv) => {
296
304
  return ({
297
305
  name: buildEnv,
298
306
  output: {
299
- path: `${outputPath}/${buildEnv}`,
307
+ path: `${outputPath}/${buildEnv === 'prod' ? '' : buildEnv}`,
300
308
  publicPath: isDev ? '/' : (_b = (_a = config_1.getGuruConfig()) === null || _a === void 0 ? void 0 : _a.publicPath) !== null && _b !== void 0 ? _b : '/',
301
309
  filename: `${fileMask}.js`,
302
310
  chunkFilename: `chunks/${fileMask}.js`,
@@ -308,7 +316,7 @@ const makeWebpackConfig = (buildEnv) => {
308
316
  });
309
317
  };
310
318
  const buildConfigs = () => buildEnvs.map((buildEnv) => ({
311
- ...baseOptions,
319
+ ...baseOptions(buildEnv),
312
320
  ...makeWebpackConfig(buildEnv),
313
321
  }));
314
322
  exports.default = buildConfigs;
@@ -20,7 +20,13 @@ const done = (resolve, reject) => (err, stats) => {
20
20
  }
21
21
  resolve();
22
22
  };
23
- const run = async (compiler) => new Promise((resolve, reject) => compiler.run(done(resolve, reject)));
23
+ const run = async (compiler) => new Promise((resolve, reject) => compiler.run((err, stats) => {
24
+ compiler.close((err2) => {
25
+ console.log(stats);
26
+ resolve(err || err2);
27
+ });
28
+ done(resolve, reject);
29
+ }));
24
30
  exports.run = run;
25
31
  const watch = async (compiler) => new Promise((resolve, reject) => compiler.watch({}, done(resolve, reject)));
26
32
  exports.watch = watch;
@@ -1 +1,2 @@
1
1
  export declare const getConfigsDirs: () => string[];
2
+ export declare const getBuildFolder: () => string[];
@@ -3,10 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfigsDirs = void 0;
6
+ exports.getBuildFolder = exports.getConfigsDirs = void 0;
7
7
  const find_up_1 = __importDefault(require("find-up"));
8
8
  const getConfigsDirs = () => [
9
9
  find_up_1.default.sync('.gdu_config', { type: 'directory' }),
10
10
  find_up_1.default.sync('.gdu_app_config', { type: 'directory' }),
11
11
  ].filter(Boolean);
12
12
  exports.getConfigsDirs = getConfigsDirs;
13
+ const getBuildFolder = () => [
14
+ find_up_1.default.sync('.gdu_config', { type: 'directory' }),
15
+ find_up_1.default.sync('.gdu_app_config', { type: 'directory' }),
16
+ ].filter(Boolean);
17
+ exports.getBuildFolder = getBuildFolder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdu",
3
- "version": "4.0.0-next.13",
3
+ "version": "4.0.0-next.17",
4
4
  "private": false,
5
5
  "description": "AutoGuru's development toolkit",
6
6
  "homepage": "https://github.com/autoguru-au/octane/tree/master/packages/gdu#readme",
@@ -82,8 +82,8 @@
82
82
  "ts-dedent": "^2.0.0",
83
83
  "tsconfig-paths-webpack-plugin": "^3.5.1",
84
84
  "url-loader": "^4.1.1",
85
- "webpack": "^5.50.0",
86
- "webpack-dev-server": "^4.0.0-rc.0",
85
+ "webpack": "^5.64.2",
86
+ "webpack-dev-server": "^4.5.0",
87
87
  "whatwg-fetch": "^3.6.2"
88
88
  },
89
89
  "devDependencies": {