Skip to content

Commit 5cda184

Browse files
committed
Do best practice deferring where possible
1 parent 69b2820 commit 5cda184

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

.config/rollup.base.config.mjs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,11 @@ const {
3737
ROLLUP_ENTRY_SUFFIX,
3838
ROLLUP_EXTERNAL_SUFFIX,
3939
SLASH_NODE_MODULES_SLASH,
40-
VENDOR,
41-
babelConfigPath,
42-
rootPackageJsonPath,
43-
rootPath,
44-
rootSrcPath,
45-
tsconfigPath
40+
VENDOR
4641
} = constants
4742

4843
const SOCKET_INTEROP = '_socketInterop'
4944

50-
const constantsSrcPath = path.join(rootSrcPath, `${CONSTANTS}.ts`)
51-
52-
const babelConfig = require(babelConfigPath)
53-
const tsPlugin = require('rollup-plugin-ts')
54-
const rootPackageJson = require(rootPackageJsonPath)
55-
56-
const {
57-
dependencies: pkgDeps,
58-
devDependencies: pkgDevDeps,
59-
overrides: pkgOverrides
60-
} = rootPackageJson
61-
6245
const builtinAliases = builtinModules.reduce((o, n) => {
6346
o[n] = `node:${n}`
6447
return o
@@ -126,6 +109,25 @@ function isAncestorsExternal(id, depStats) {
126109
}
127110

128111
export default function baseConfig(extendConfig = {}) {
112+
// Lazily access constants props.
113+
const {
114+
babelConfigPath,
115+
rootPackageJsonPath,
116+
rootPath,
117+
rootSrcPath,
118+
tsconfigPath
119+
} = constants
120+
121+
const {
122+
dependencies: pkgDeps,
123+
devDependencies: pkgDevDeps,
124+
overrides: pkgOverrides
125+
} = require(rootPackageJsonPath)
126+
127+
const constantsSrcPath = path.join(rootSrcPath, `${CONSTANTS}.ts`)
128+
const babelConfig = require(babelConfigPath)
129+
const tsPlugin = require('rollup-plugin-ts')
130+
129131
const depStats = {
130132
dependencies: { __proto__: null },
131133
devDependencies: { __proto__: null },

.config/rollup.test.config.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ import {
99
normalizeId
1010
} from '../scripts/utils/packages.js'
1111

12-
const {
13-
BABEL_RUNTIME,
14-
ROLLUP_EXTERNAL_SUFFIX,
15-
SUPPORTS_SYNC_ESM,
16-
rootSrcPath
17-
} = constants
12+
const { BABEL_RUNTIME, ROLLUP_EXTERNAL_SUFFIX } = constants
1813

19-
export default () =>
20-
baseConfig({
14+
export default () => {
15+
// Lazily access constants.rootSrcPath
16+
const { rootSrcPath } = constants
17+
return baseConfig({
2118
input: {
2219
'alert-rules': `${rootSrcPath}/utils/alert/rules.ts`,
2320
errors: `${rootSrcPath}/utils/errors.ts`,
@@ -35,7 +32,8 @@ export default () =>
3532
sourcemapDebugIds: true
3633
}
3734
],
38-
...(SUPPORTS_SYNC_ESM
35+
// Lazily access constants.SUPPORTS_SYNC_ESM
36+
...(constants.SUPPORTS_SYNC_ESM
3937
? {
4038
external(id_) {
4139
if (id_.endsWith(ROLLUP_EXTERNAL_SUFFIX) || isBuiltin(id_)) {
@@ -58,3 +56,4 @@ export default () =>
5856
}
5957
: {})
6058
})
59+
}

0 commit comments

Comments
 (0)