@pushwoosh/frontend-builder-engine 3.0.1 → 3.1.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.
@@ -1,26 +1,47 @@
1
+ // Every preset and plugin below is resolved against this file instead of being
2
+ // named as a bare specifier. Babel resolves bare names relative to the config
3
+ // that declares them — i.e. the consuming project's babel.config.js — and npm
4
+ // keeps our @babel/* copies nested under the engine whenever the consumer's
5
+ // tree holds a conflicting version, which makes them invisible from there.
6
+ const fromEngine = (name) => require.resolve(name);
7
+
8
+ // Same reasoning for the helper runtime, via absoluteRuntime below. Passing our
9
+ // own version matters too: the plugin defaults to `version: "7.0.0-beta.0"` and
10
+ // silently inlines every helper it thinks that version lacks, instead of
11
+ // importing it.
12
+ const runtimeVersion = require('@babel/runtime/package.json').version;
13
+
14
+ const { BROWSER_TARGETS } = require('./browser-targets');
15
+
1
16
  module.exports = (api) => {
2
17
  api.cache(true);
3
18
  return {
19
+ // Declared here rather than left to a project .browserslistrc: without any
20
+ // targets preset-env compiles all the way down to ES5, regenerator and all.
21
+ targets: BROWSER_TARGETS,
4
22
  presets: [
5
- '@babel/preset-env',
23
+ fromEngine('@babel/preset-env'),
6
24
  [
7
- '@babel/preset-react',
25
+ fromEngine('@babel/preset-react'),
8
26
  {
9
27
  'runtime': 'automatic'
10
28
  }
11
29
  ],
12
- '@babel/preset-typescript'
30
+ fromEngine('@babel/preset-typescript')
13
31
  ],
14
32
  plugins: [
15
33
  [
16
- '@babel/plugin-transform-runtime',
34
+ fromEngine('@babel/plugin-transform-runtime'),
17
35
  {
18
- 'useESModules': true,
19
- 'regenerator': true
36
+ version: runtimeVersion,
37
+ absoluteRuntime: __dirname,
38
+ // babel-loader reports supportsStaticESM, so this picks helpers/esm
39
+ // under webpack and CJS helpers anywhere else.
40
+ useESModules: 'auto',
20
41
  }
21
42
  ],
22
43
  [
23
- 'babel-plugin-styled-components',
44
+ fromEngine('babel-plugin-styled-components'),
24
45
  {
25
46
  minify: true,
26
47
  transpileTemplateLiterals: true,
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Single source of truth for the browser floor. Consumed by two places that
3
+ * would otherwise each resolve it independently:
4
+ *
5
+ * - `babel.application.config.js` passes it to preset-env as `targets`
6
+ * - `webpack-config/single-spa-defaults.js` exports it as `process.env.BROWSERSLIST`
7
+ *
8
+ * Declaring it here rather than expecting a `.browserslistrc` in every project
9
+ * keeps the floor from drifting per repository. Both mechanisms deliberately
10
+ * override any project-level browserslist config: an explicit `targets` beats a
11
+ * config file in babel, and the BROWSERSLIST variable short-circuits config
12
+ * lookup in browserslist itself.
13
+ *
14
+ * This is an honest ES2022 baseline — these are exactly the versions where the
15
+ * last ES2022 feature (class static initialization blocks) landed. Keep it in
16
+ * sync with `target`/`lib` in `lib/tsconfig.json`: library packages are emitted
17
+ * at that target and are never re-transpiled, because babel-loader excludes
18
+ * node_modules.
19
+ *
20
+ * Constraints if you ever move this floor:
21
+ * - preset-env runs without useBuiltIns/core-js, so new builtins go out
22
+ * unpolyfilled regardless of what is declared here. Do not drop below
23
+ * Safari 15.4 — dependencies ship Object.hasOwn.
24
+ * - Below Safari/iOS 16.3 preset-env turns on transform-parameters (default
25
+ * and rest params rewritten to `arguments` in every function) plus the
26
+ * static-block transform: roughly +5.8 KB raw / +0.9 KB gzip.
27
+ * - Below Chrome/Edge 91 it enables
28
+ * plugin-bugfix-v8-spread-parameters-in-optional-chaining, which downlevels
29
+ * every `?.` in the bundle.
30
+ */
31
+ const BROWSER_TARGETS = [
32
+ 'Chrome >= 94',
33
+ 'Edge >= 94',
34
+ 'Firefox >= 93',
35
+ 'Safari >= 16.4',
36
+ 'iOS >= 16.4',
37
+ ];
38
+
39
+ module.exports = {
40
+ BROWSER_TARGETS,
41
+ BROWSERSLIST_QUERY: BROWSER_TARGETS.join(', '),
42
+ };
@@ -8,6 +8,13 @@ async function buildStyledComponents(
8
8
  targetDir,
9
9
  ) {
10
10
  const files = await listFilesInDirectoryRecursively(sourceDir);
11
+ // Only styled-components runs here. `?.` is deliberately left alone: tsc
12
+ // already emits it untouched at the ES2022 target, and every browser in
13
+ // lib/browser-targets.js supports it natively. The optional-chaining
14
+ // transform this used to carry was a leftover from when it was a proposal —
15
+ // it also depended on @babel/plugin-transform-optional-chaining resolving
16
+ // transitively through preset-env's tree, since it was never a declared
17
+ // dependency of this package.
11
18
  const options = {
12
19
  babelrc: false,
13
20
  configFile: false,
@@ -20,7 +27,6 @@ async function buildStyledComponents(
20
27
  transpileTemplateLiterals: true,
21
28
  },
22
29
  ],
23
- require.resolve('@babel/plugin-transform-optional-chaining'),
24
30
  ],
25
31
  };
26
32
  const jsFiles = files.filter((file) => file.endsWith('.js'));
package/lib/tsconfig.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* ----- Base Options ----- */
4
+ /* Keep `lib` pinned to `target`: preset-env runs without useBuiltIns/core-js,
5
+ so anything newer than ES2022 that the checker allows ships unpolyfilled.
6
+ Must stay in sync with the browser floor in lib/browser-targets.js, which
7
+ is where the engine declares it — consuming projects need no
8
+ .browserslistrc of their own. */
4
9
  "target": "ES2022",
5
10
  "module": "ESNext",
6
11
  "lib": [
7
- "ESNext",
12
+ "ES2022",
8
13
  "DOM"
9
14
  ],
10
15
  "outDir": "./dist",
@@ -3,6 +3,16 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
3
3
  const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
4
4
  const SystemJSPublicPathPlugin = require('systemjs-webpack-interop/SystemJSPublicPathWebpackPlugin');
5
5
 
6
+ const { BROWSERSLIST_QUERY } = require('../browser-targets');
7
+
8
+ // browserslist reads this before it looks for any config file (see loadConfig
9
+ // in browserslist/node.js), so it makes the engine authoritative even when a
10
+ // project still carries a stray .browserslistrc. Passing the query inline as
11
+ // `target: 'browserslist:<query>'` does NOT achieve this: webpack's handler
12
+ // only falls back to treating the string as a query when no project config was
13
+ // found at all, so a project file would silently win.
14
+ process.env.BROWSERSLIST = BROWSERSLIST_QUERY;
15
+
6
16
  /**
7
17
  * Single-spa webpack configuration for React + TypeScript applications.
8
18
  * Replaces webpack-config-single-spa-react-ts package.
@@ -63,6 +73,10 @@ function singleSpaDefaults(opts) {
63
73
 
64
74
  return {
65
75
  mode: isProduction ? 'production' : 'development',
76
+ // Without this webpack falls back to 'web' when no browserslist config is
77
+ // visible — a second, drifting source of truth for the floor. Resolves
78
+ // against the BROWSERSLIST value set above.
79
+ target: 'browserslist',
66
80
  entry: path.resolve(
67
81
  process.cwd(),
68
82
  `src/${opts.orgName}-${opts.projectName}.tsx`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/frontend-builder-engine",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "Pushwoosh frontend builder engine",
5
5
  "main": "./lib/pushwoosh-frontend-builder-engine.js",
6
6
  "publishConfig": {
@@ -25,6 +25,7 @@
25
25
  "@babel/preset-env": "^7.24.3",
26
26
  "@babel/preset-react": "^7.24.1",
27
27
  "@babel/preset-typescript": "^7.24.1",
28
+ "@babel/runtime": "^7.29.7",
28
29
  "@babel/types": "^7.24.0",
29
30
  "@eslint/js": "^9.13.0",
30
31
  "@stylistic/eslint-plugin": "^5.3.1",