@docusaurus/babel 3.5.2
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/README.md +3 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -0
- package/lib/preset.d.ts +9 -0
- package/lib/preset.d.ts.map +1 -0
- package/lib/preset.js +81 -0
- package/lib/preset.js.map +1 -0
- package/lib/utils.d.ts +13 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +39 -0
- package/lib/utils.js.map +1 -0
- package/package.json +47 -0
- package/src/index.ts +8 -0
- package/src/preset.ts +82 -0
- package/src/utils.ts +50 -0
package/README.md
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export { getCustomBabelConfigFilePath, getBabelOptions } from './utils';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,4BAA4B,EAAE,eAAe,EAAC,MAAM,SAAS,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getBabelOptions = exports.getCustomBabelConfigFilePath = void 0;
|
|
10
|
+
var utils_1 = require("./utils");
|
|
11
|
+
Object.defineProperty(exports, "getCustomBabelConfigFilePath", { enumerable: true, get: function () { return utils_1.getCustomBabelConfigFilePath; } });
|
|
12
|
+
Object.defineProperty(exports, "getBabelOptions", { enumerable: true, get: function () { return utils_1.getBabelOptions; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAAsE;AAA9D,qHAAA,4BAA4B,OAAA;AAAE,wGAAA,eAAe,OAAA"}
|
package/lib/preset.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConfigAPI, TransformOptions } from '@babel/core';
|
|
8
|
+
export default function babelPresets(api: ConfigAPI): TransformOptions;
|
|
9
|
+
//# sourceMappingURL=preset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,SAAS,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAsE7D,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,gBAAgB,CAGrE"}
|
package/lib/preset.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = babelPresets;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
function getTransformOptions(isServer) {
|
|
13
|
+
const absoluteRuntimePath = path_1.default.dirname(require.resolve(`@babel/runtime/package.json`));
|
|
14
|
+
return {
|
|
15
|
+
// All optional newlines and whitespace will be omitted when generating code
|
|
16
|
+
// in compact mode
|
|
17
|
+
compact: true,
|
|
18
|
+
presets: [
|
|
19
|
+
isServer
|
|
20
|
+
? [
|
|
21
|
+
require.resolve('@babel/preset-env'),
|
|
22
|
+
{
|
|
23
|
+
targets: {
|
|
24
|
+
node: 'current',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
: [
|
|
29
|
+
require.resolve('@babel/preset-env'),
|
|
30
|
+
{
|
|
31
|
+
useBuiltIns: 'entry',
|
|
32
|
+
loose: true,
|
|
33
|
+
corejs: '3',
|
|
34
|
+
// Do not transform modules to CJS
|
|
35
|
+
modules: false,
|
|
36
|
+
// Exclude transforms that make all code slower
|
|
37
|
+
exclude: ['transform-typeof-symbol'],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
require.resolve('@babel/preset-react'),
|
|
42
|
+
{
|
|
43
|
+
runtime: 'automatic',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
require.resolve('@babel/preset-typescript'),
|
|
47
|
+
],
|
|
48
|
+
plugins: [
|
|
49
|
+
// Polyfills the runtime needed for async/await, generators, and friends
|
|
50
|
+
// https://babeljs.io/docs/en/babel-plugin-transform-runtime
|
|
51
|
+
[
|
|
52
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
53
|
+
{
|
|
54
|
+
corejs: false,
|
|
55
|
+
helpers: true,
|
|
56
|
+
// By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0,
|
|
57
|
+
// better to explicitly specify the version so that it can reuse the
|
|
58
|
+
// helper better. See https://github.com/babel/babel/issues/10261
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
|
60
|
+
version: require('@babel/runtime/package.json')
|
|
61
|
+
.version,
|
|
62
|
+
regenerator: true,
|
|
63
|
+
useESModules: true,
|
|
64
|
+
// Undocumented option that lets us encapsulate our runtime, ensuring
|
|
65
|
+
// the correct version is used
|
|
66
|
+
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
|
|
67
|
+
absoluteRuntime: absoluteRuntimePath,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
// Adds syntax support for import()
|
|
71
|
+
isServer
|
|
72
|
+
? require.resolve('babel-plugin-dynamic-import-node')
|
|
73
|
+
: require.resolve('@babel/plugin-syntax-dynamic-import'),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function babelPresets(api) {
|
|
78
|
+
const callerName = api.caller((caller) => caller?.name);
|
|
79
|
+
return getTransformOptions(callerName === 'server');
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=preset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAyEH,+BAGC;;AA1ED,wDAAwB;AAGxB,SAAS,mBAAmB,CAAC,QAAiB;IAC5C,MAAM,mBAAmB,GAAG,cAAI,CAAC,OAAO,CACtC,OAAO,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAC/C,CAAC;IACF,OAAO;QACL,4EAA4E;QAC5E,kBAAkB;QAClB,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP,QAAQ;gBACN,CAAC,CAAC;oBACE,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC;oBACpC;wBACE,OAAO,EAAE;4BACP,IAAI,EAAE,SAAS;yBAChB;qBACF;iBACF;gBACH,CAAC,CAAC;oBACE,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC;oBACpC;wBACE,WAAW,EAAE,OAAO;wBACpB,KAAK,EAAE,IAAI;wBACX,MAAM,EAAE,GAAG;wBACX,kCAAkC;wBAClC,OAAO,EAAE,KAAK;wBACd,+CAA+C;wBAC/C,OAAO,EAAE,CAAC,yBAAyB,CAAC;qBACrC;iBACF;YACL;gBACE,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC;gBACtC;oBACE,OAAO,EAAE,WAAW;iBACrB;aACF;YACD,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC;SAC5C;QACD,OAAO,EAAE;YACP,wEAAwE;YACxE,4DAA4D;YAC5D;gBACE,OAAO,CAAC,OAAO,CAAC,iCAAiC,CAAC;gBAClD;oBACE,MAAM,EAAE,KAAK;oBACb,OAAO,EAAE,IAAI;oBACb,oEAAoE;oBACpE,oEAAoE;oBACpE,iEAAiE;oBACjE,8EAA8E;oBAC9E,OAAO,EAAG,OAAO,CAAC,6BAA6B,CAAuB;yBACnE,OAAO;oBACV,WAAW,EAAE,IAAI;oBACjB,YAAY,EAAE,IAAI;oBAClB,qEAAqE;oBACrE,8BAA8B;oBAC9B,4IAA4I;oBAC5I,eAAe,EAAE,mBAAmB;iBACrC;aACF;YACD,mCAAmC;YACnC,QAAQ;gBACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC;gBACrD,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,qCAAqC,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC;AAED,SAAwB,YAAY,CAAC,GAAc;IACjD,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACxD,OAAO,mBAAmB,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;AACtD,CAAC"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { TransformOptions } from '@babel/core';
|
|
8
|
+
export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
|
|
9
|
+
export declare function getBabelOptions({ isServer, babelOptions, }?: {
|
|
10
|
+
isServer?: boolean;
|
|
11
|
+
babelOptions?: TransformOptions | string;
|
|
12
|
+
}): TransformOptions;
|
|
13
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAElD,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAQ7B;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,YAAY,GACb,GAAE;IACD,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,YAAY,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;CACrC,GAAG,gBAAgB,CAiBxB"}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getCustomBabelConfigFilePath = getCustomBabelConfigFilePath;
|
|
10
|
+
exports.getBabelOptions = getBabelOptions;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
async function getCustomBabelConfigFilePath(siteDir) {
|
|
16
|
+
const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
|
|
17
|
+
return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
|
|
18
|
+
? customBabelConfigurationPath
|
|
19
|
+
: undefined;
|
|
20
|
+
}
|
|
21
|
+
function getBabelOptions({ isServer, babelOptions, } = {}) {
|
|
22
|
+
const caller = { name: isServer ? 'server' : 'client' };
|
|
23
|
+
if (typeof babelOptions === 'string') {
|
|
24
|
+
return {
|
|
25
|
+
babelrc: false,
|
|
26
|
+
configFile: babelOptions,
|
|
27
|
+
caller,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...(babelOptions ?? {
|
|
32
|
+
presets: [require.resolve('@docusaurus/babel/preset')],
|
|
33
|
+
}),
|
|
34
|
+
babelrc: false,
|
|
35
|
+
configFile: false,
|
|
36
|
+
caller,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAOH,oEAUC;AAED,0CAyBC;;AA1CD,gEAA0B;AAC1B,wDAAwB;AACxB,6CAAyD;AAGlD,KAAK,UAAU,4BAA4B,CAChD,OAAe;IAEf,MAAM,4BAA4B,GAAG,cAAI,CAAC,IAAI,CAC5C,OAAO,EACP,8BAAsB,CACvB,CAAC;IACF,OAAO,CAAC,MAAM,kBAAE,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAC;QACxD,CAAC,CAAC,4BAA4B;QAC9B,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,YAAY,MAMV,EAAE;IACJ,MAAM,MAAM,GAAG,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAC,CAAC;IACtD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,YAAY;YACxB,MAAM;SACP,CAAC;IACJ,CAAC;IACD,OAAO;QACL,GAAG,CAAC,YAAY,IAAI;YAClB,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;SACvD,CAAC;QACF,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,KAAK;QACjB,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@docusaurus/babel",
|
|
3
|
+
"version": "3.5.2",
|
|
4
|
+
"description": "Docusaurus package for Babel-related utils.",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./preset": {
|
|
9
|
+
"types": "./lib/preset.d.ts",
|
|
10
|
+
"default": "./lib/preset.js"
|
|
11
|
+
},
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"watch": "tsc --watch"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/facebook/docusaurus.git",
|
|
27
|
+
"directory": "packages/docusaurus-babel"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@babel/core": "^7.23.3",
|
|
32
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
33
|
+
"@babel/plugin-transform-runtime": "^7.22.9",
|
|
34
|
+
"@babel/preset-env": "^7.22.9",
|
|
35
|
+
"@babel/preset-react": "^7.22.5",
|
|
36
|
+
"@babel/preset-typescript": "^7.22.5",
|
|
37
|
+
"@babel/runtime": "^7.22.6",
|
|
38
|
+
"@babel/runtime-corejs3": "^7.22.6",
|
|
39
|
+
"@docusaurus/utils": "3.5.2",
|
|
40
|
+
"babel-loader": "^9.1.3",
|
|
41
|
+
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
42
|
+
"fs-extra": "^11.1.1"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18.0"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export {getCustomBabelConfigFilePath, getBabelOptions} from './utils';
|
package/src/preset.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import type {ConfigAPI, TransformOptions} from '@babel/core';
|
|
10
|
+
|
|
11
|
+
function getTransformOptions(isServer: boolean): TransformOptions {
|
|
12
|
+
const absoluteRuntimePath = path.dirname(
|
|
13
|
+
require.resolve(`@babel/runtime/package.json`),
|
|
14
|
+
);
|
|
15
|
+
return {
|
|
16
|
+
// All optional newlines and whitespace will be omitted when generating code
|
|
17
|
+
// in compact mode
|
|
18
|
+
compact: true,
|
|
19
|
+
presets: [
|
|
20
|
+
isServer
|
|
21
|
+
? [
|
|
22
|
+
require.resolve('@babel/preset-env'),
|
|
23
|
+
{
|
|
24
|
+
targets: {
|
|
25
|
+
node: 'current',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
]
|
|
29
|
+
: [
|
|
30
|
+
require.resolve('@babel/preset-env'),
|
|
31
|
+
{
|
|
32
|
+
useBuiltIns: 'entry',
|
|
33
|
+
loose: true,
|
|
34
|
+
corejs: '3',
|
|
35
|
+
// Do not transform modules to CJS
|
|
36
|
+
modules: false,
|
|
37
|
+
// Exclude transforms that make all code slower
|
|
38
|
+
exclude: ['transform-typeof-symbol'],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
require.resolve('@babel/preset-react'),
|
|
43
|
+
{
|
|
44
|
+
runtime: 'automatic',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
require.resolve('@babel/preset-typescript'),
|
|
48
|
+
],
|
|
49
|
+
plugins: [
|
|
50
|
+
// Polyfills the runtime needed for async/await, generators, and friends
|
|
51
|
+
// https://babeljs.io/docs/en/babel-plugin-transform-runtime
|
|
52
|
+
[
|
|
53
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
54
|
+
{
|
|
55
|
+
corejs: false,
|
|
56
|
+
helpers: true,
|
|
57
|
+
// By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0,
|
|
58
|
+
// better to explicitly specify the version so that it can reuse the
|
|
59
|
+
// helper better. See https://github.com/babel/babel/issues/10261
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
|
61
|
+
version: (require('@babel/runtime/package.json') as {version: string})
|
|
62
|
+
.version,
|
|
63
|
+
regenerator: true,
|
|
64
|
+
useESModules: true,
|
|
65
|
+
// Undocumented option that lets us encapsulate our runtime, ensuring
|
|
66
|
+
// the correct version is used
|
|
67
|
+
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
|
|
68
|
+
absoluteRuntime: absoluteRuntimePath,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
// Adds syntax support for import()
|
|
72
|
+
isServer
|
|
73
|
+
? require.resolve('babel-plugin-dynamic-import-node')
|
|
74
|
+
: require.resolve('@babel/plugin-syntax-dynamic-import'),
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default function babelPresets(api: ConfigAPI): TransformOptions {
|
|
80
|
+
const callerName = api.caller((caller) => caller?.name);
|
|
81
|
+
return getTransformOptions(callerName === 'server');
|
|
82
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import {BABEL_CONFIG_FILE_NAME} from '@docusaurus/utils';
|
|
11
|
+
import type {TransformOptions} from '@babel/core';
|
|
12
|
+
|
|
13
|
+
export async function getCustomBabelConfigFilePath(
|
|
14
|
+
siteDir: string,
|
|
15
|
+
): Promise<string | undefined> {
|
|
16
|
+
const customBabelConfigurationPath = path.join(
|
|
17
|
+
siteDir,
|
|
18
|
+
BABEL_CONFIG_FILE_NAME,
|
|
19
|
+
);
|
|
20
|
+
return (await fs.pathExists(customBabelConfigurationPath))
|
|
21
|
+
? customBabelConfigurationPath
|
|
22
|
+
: undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getBabelOptions({
|
|
26
|
+
isServer,
|
|
27
|
+
babelOptions,
|
|
28
|
+
}: {
|
|
29
|
+
isServer?: boolean;
|
|
30
|
+
// TODO Docusaurus v4 fix this
|
|
31
|
+
// weird to have getBabelOptions take a babelOptions param
|
|
32
|
+
babelOptions?: TransformOptions | string;
|
|
33
|
+
} = {}): TransformOptions {
|
|
34
|
+
const caller = {name: isServer ? 'server' : 'client'};
|
|
35
|
+
if (typeof babelOptions === 'string') {
|
|
36
|
+
return {
|
|
37
|
+
babelrc: false,
|
|
38
|
+
configFile: babelOptions,
|
|
39
|
+
caller,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...(babelOptions ?? {
|
|
44
|
+
presets: [require.resolve('@docusaurus/babel/preset')],
|
|
45
|
+
}),
|
|
46
|
+
babelrc: false,
|
|
47
|
+
configFile: false,
|
|
48
|
+
caller,
|
|
49
|
+
};
|
|
50
|
+
}
|