@docusaurus/faster 3.9.2 → 3.10.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.
package/lib/index.d.ts CHANGED
@@ -8,15 +8,18 @@ import Rspack from '@rspack/core';
8
8
  import * as lightningcss from 'lightningcss';
9
9
  import { minify as swcHtmlMinifier } from '@swc/html';
10
10
  import type { JsMinifyOptions, Options as SwcOptions } from '@swc/core';
11
+ import type { CurrentBundler } from '@docusaurus/types';
11
12
  export declare const swcLoader: string;
12
- export declare const getSwcLoaderOptions: ({ isServer, }: {
13
+ export declare const getSwcLoaderOptions: ({ isServer, bundlerName, }: {
13
14
  isServer: boolean;
15
+ bundlerName: CurrentBundler["name"];
14
16
  }) => SwcOptions;
15
17
  export declare const rspack: typeof Rspack;
16
18
  export declare function getSwcHtmlMinifier(): typeof swcHtmlMinifier;
17
19
  export declare function getSwcJsMinimizerOptions(): JsMinifyOptions;
18
- export declare function getBrowserslistQueries({ isServer, }: {
20
+ export declare function getBrowserslistQueries({ isServer, bundlerName, }: {
19
21
  isServer: boolean;
22
+ bundlerName: CurrentBundler['name'];
20
23
  }): string[];
21
24
  type LightningCssMinimizerOptions = Omit<lightningcss.TransformOptions<never>, 'filename' | 'code'>;
22
25
  export declare function getLightningCssMinimizerOptions(): LightningCssMinimizerOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,YAAY,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAC,MAAM,IAAI,eAAe,EAAC,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,IAAI,UAAU,EAAC,MAAM,WAAW,CAAC;AAEtE,eAAO,MAAM,SAAS,QAAgC,CAAC;AAEvD,eAAO,MAAM,mBAAmB,GAAI,eAEjC;IACD,QA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AC;IAClB,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACrC,GAAG,MAAM,EAAE,CAqBX;AAKD,KAAK,4BAA4B,GAAG,IAAI,CACtC,YAAY,CAAC,gBAAgB,CAAC,KAAK,CAAC,EACpC,UAAU,GAAG,MAAM,CACpB,CAAC;AAEF,wBAAgB,+BAA+B,IAAI,4BAA4B,CAG9E"}
package/lib/index.js CHANGED
@@ -16,11 +16,12 @@ const core_1 = tslib_1.__importDefault(require("@rspack/core"));
16
16
  const lightningcss = tslib_1.__importStar(require("lightningcss"));
17
17
  const browserslist_1 = tslib_1.__importDefault(require("browserslist"));
18
18
  const html_1 = require("@swc/html");
19
+ const semver_1 = tslib_1.__importDefault(require("semver"));
19
20
  exports.swcLoader = require.resolve('swc-loader');
20
- const getSwcLoaderOptions = ({ isServer, }) => {
21
+ const getSwcLoaderOptions = ({ isServer, bundlerName, }) => {
21
22
  return {
22
23
  env: {
23
- targets: getBrowserslistQueries({ isServer }),
24
+ targets: getBrowserslistQueries({ isServer, bundlerName }),
24
25
  },
25
26
  jsc: {
26
27
  parser: {
@@ -60,11 +61,33 @@ function getSwcJsMinimizerOptions() {
60
61
  },
61
62
  };
62
63
  }
64
+ // TODO this is not accurate
65
+ // for Rspack we should read from the built-in browserslist data
66
+ // see https://github.com/facebook/docusaurus/pull/11496
67
+ function getLastBrowserslistKnownNodeVersion(bundlerName) {
68
+ if (bundlerName === 'rspack') {
69
+ // TODO hardcoded value until Rspack exposes its Browserslist data
70
+ // see https://github.com/facebook/docusaurus/pull/11496
71
+ return '22.0.0';
72
+ }
73
+ // browserslist('last 1 node versions')[0]!.replace('node ', '')
74
+ return browserslist_1.default.nodeVersions.at(-1);
75
+ }
76
+ function getMinVersion(v1, v2) {
77
+ return semver_1.default.lt(v1, v2) ? v1 : v2;
78
+ }
63
79
  // We need this because of Rspack built-in LightningCSS integration
64
80
  // See https://github.com/orgs/browserslist/discussions/846
65
- function getBrowserslistQueries({ isServer, }) {
81
+ function getBrowserslistQueries({ isServer, bundlerName, }) {
66
82
  if (isServer) {
67
- return [`node ${process.versions.node}`];
83
+ // Escape hatch env variable
84
+ if (process.env.DOCUSAURUS_SERVER_NODE_TARGET) {
85
+ return [`node ${process.env.DOCUSAURUS_SERVER_NODE_TARGET}`];
86
+ }
87
+ // For server builds, we want to use the current Node version as target
88
+ // But we can't pass a target that Browserslist doesn't know about yet
89
+ const nodeTarget = getMinVersion(process.versions.node, getLastBrowserslistKnownNodeVersion(bundlerName));
90
+ return [`node ${nodeTarget}`];
68
91
  }
69
92
  const queries = browserslist_1.default.loadConfig({ path: process.cwd() }) ?? [
70
93
  ...browserslist_1.default.defaults,
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAmCH,gDAEC;AAMD,4DAeC;AAID,wDAaC;AAUD,0EAGC;;AAtFD,gEAAkC;AAClC,mEAA6C;AAC7C,wEAAwC;AACxC,oCAAoD;AAGvC,QAAA,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAEhD,MAAM,mBAAmB,GAAG,CAAC,EAClC,QAAQ,GAGT,EAAc,EAAE;IACf,OAAO;QACL,GAAG,EAAE;YACH,OAAO,EAAE,sBAAsB,CAAC,EAAC,QAAQ,EAAC,CAAC;SAC5C;QACD,GAAG,EAAE;YACH,MAAM,EAAE;gBACN,MAAM,EAAE,YAAY;gBACpB,GAAG,EAAE,IAAI;aACV;YACD,SAAS,EAAE;gBACT,KAAK,EAAE;oBACL,OAAO,EAAE,WAAW;iBACrB;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,mBAAmB,uBAqB9B;AAEW,QAAA,MAAM,GAAkB,cAAM,CAAC;AAE5C,SAAgB,kBAAkB;IAChC,OAAO,aAAe,CAAC;AACzB,CAAC;AAED,yDAAyD;AACzD,8EAA8E;AAC9E,gFAAgF;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A2D;AAC3D,SAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,WAAW,GAIZ;IACC,IAAI,QAAQ,EAAE,CAAC;QACb,4BAA4B;QAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,CAAC;YAC9C,OAAO,CAAC,QAAQ,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,uEAAuE;QACvE,sEAAsE;QACtE,MAAM,UAAU,GAAG,aAAa,CAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,EACrB,mCAAmC,CAAC,WAAW,CAAC,CACjD,CAAC;QAEF,OAAO,CAAC,QAAQ,UAAU,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,OAAO,GAAG,sBAAY,CAAC,UAAU,CAAC,EAAC,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE,EAAC,CAAC,IAAI;QAChE,GAAG,sBAAY,CAAC,QAAQ;KACzB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAUD,SAAgB,+BAA+B;IAC7C,MAAM,OAAO,GAAG,IAAA,sBAAY,GAAE,CAAC;IAC/B,OAAO,EAAC,OAAO,EAAE,YAAY,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAC,CAAC;AAChE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/faster",
3
- "version": "3.9.2",
3
+ "version": "3.10.1",
4
4
  "description": "Docusaurus experimental package exposing new modern dependencies to make the build faster.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,12 +18,13 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/types": "3.9.2",
22
- "@rspack/core": "^1.5.0",
21
+ "@docusaurus/types": "3.10.1",
22
+ "@rspack/core": "^1.7.10",
23
23
  "@swc/core": "^1.7.39",
24
24
  "@swc/html": "^1.13.5",
25
25
  "browserslist": "^4.24.2",
26
26
  "lightningcss": "^1.27.0",
27
+ "semver": "^7.5.4",
27
28
  "swc-loader": "^0.2.6",
28
29
  "tslib": "^2.6.0",
29
30
  "webpack": "^5.95.0"
@@ -34,5 +35,5 @@
34
35
  "peerDependencies": {
35
36
  "@docusaurus/types": "*"
36
37
  },
37
- "gitHead": "abfbe5621b08407bc3dcbe6111ff118d4c22f7a1"
38
+ "gitHead": "41c1a458ecb07d61b6df2761ea4bc1b13db49d12"
38
39
  }
package/src/index.ts CHANGED
@@ -9,18 +9,22 @@ import Rspack from '@rspack/core';
9
9
  import * as lightningcss from 'lightningcss';
10
10
  import browserslist from 'browserslist';
11
11
  import {minify as swcHtmlMinifier} from '@swc/html';
12
+ import semver from 'semver';
12
13
  import type {JsMinifyOptions, Options as SwcOptions} from '@swc/core';
14
+ import type {CurrentBundler} from '@docusaurus/types';
13
15
 
14
16
  export const swcLoader = require.resolve('swc-loader');
15
17
 
16
18
  export const getSwcLoaderOptions = ({
17
19
  isServer,
20
+ bundlerName,
18
21
  }: {
19
22
  isServer: boolean;
23
+ bundlerName: CurrentBundler['name'];
20
24
  }): SwcOptions => {
21
25
  return {
22
26
  env: {
23
- targets: getBrowserslistQueries({isServer}),
27
+ targets: getBrowserslistQueries({isServer, bundlerName}),
24
28
  },
25
29
  jsc: {
26
30
  parser: {
@@ -63,20 +67,53 @@ export function getSwcJsMinimizerOptions(): JsMinifyOptions {
63
67
  };
64
68
  }
65
69
 
70
+ // TODO this is not accurate
71
+ // for Rspack we should read from the built-in browserslist data
72
+ // see https://github.com/facebook/docusaurus/pull/11496
73
+ function getLastBrowserslistKnownNodeVersion(
74
+ bundlerName: CurrentBundler['name'],
75
+ ): string {
76
+ if (bundlerName === 'rspack') {
77
+ // TODO hardcoded value until Rspack exposes its Browserslist data
78
+ // see https://github.com/facebook/docusaurus/pull/11496
79
+ return '22.0.0';
80
+ }
81
+ // browserslist('last 1 node versions')[0]!.replace('node ', '')
82
+ return browserslist.nodeVersions.at(-1)!;
83
+ }
84
+
85
+ function getMinVersion(v1: string, v2: string): string {
86
+ return semver.lt(v1, v2) ? v1 : v2;
87
+ }
88
+
66
89
  // We need this because of Rspack built-in LightningCSS integration
67
90
  // See https://github.com/orgs/browserslist/discussions/846
68
91
  export function getBrowserslistQueries({
69
92
  isServer,
93
+ bundlerName,
70
94
  }: {
71
95
  isServer: boolean;
96
+ bundlerName: CurrentBundler['name'];
72
97
  }): string[] {
73
98
  if (isServer) {
74
- return [`node ${process.versions.node}`];
99
+ // Escape hatch env variable
100
+ if (process.env.DOCUSAURUS_SERVER_NODE_TARGET) {
101
+ return [`node ${process.env.DOCUSAURUS_SERVER_NODE_TARGET}`];
102
+ }
103
+ // For server builds, we want to use the current Node version as target
104
+ // But we can't pass a target that Browserslist doesn't know about yet
105
+ const nodeTarget = getMinVersion(
106
+ process.versions.node,
107
+ getLastBrowserslistKnownNodeVersion(bundlerName),
108
+ );
109
+
110
+ return [`node ${nodeTarget}`];
75
111
  }
76
112
 
77
113
  const queries = browserslist.loadConfig({path: process.cwd()}) ?? [
78
114
  ...browserslist.defaults,
79
115
  ];
116
+
80
117
  return queries;
81
118
  }
82
119