Skip to content

Commit 5ac330f

Browse files
committed
Address lazy export review follow-ups
1 parent 2347d87 commit 5ac330f

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

package/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ interface ShakapackerExports {
3131
* Direct assignment (`shakapacker.baseConfig = custom`) overrides the value read back here. It only
3232
* changes `generateWebpackConfig` output in the fallback case where no `environments/<NODE_ENV>.js`
3333
* file exists; normal NODE_ENV builds load `environments/<env>.js` (which require the real base) and
34-
* are unaffected. `Object.defineProperty` with a value descriptor bypasses the setter entirely.
34+
* are unaffected. `Object.defineProperty` with a value descriptor bypasses the setter entirely and
35+
* does not propagate to `generateWebpackConfig`; direct assignment is the only path that affects
36+
* config generation.
3537
*/
3638
baseConfig: Configuration
3739
/** Environment configuration (railsEnv, nodeEnv, etc.) */

package/index.d.ts.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ interface ShakapackerExports {
3131
* Direct assignment (`shakapacker.baseConfig = custom`) overrides the value read back here. It only
3232
* changes `generateWebpackConfig` output in the fallback case where no `environments/<NODE_ENV>.js`
3333
* file exists; normal NODE_ENV builds load `environments/<env>.js` (which require the real base) and
34-
* are unaffected. `Object.defineProperty` with a value descriptor bypasses the setter entirely.
34+
* are unaffected. `Object.defineProperty` with a value descriptor bypasses the setter entirely and
35+
* does not propagate to `generateWebpackConfig`; direct assignment is the only path that affects
36+
* config generation.
3537
*/
3638
baseConfig: Configuration
3739
/** Environment configuration (railsEnv, nodeEnv, etc.) */

test/package/indexTypes.test.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { execFileSync } = require("child_process")
22
const {
3-
existsSync,
43
mkdtempSync,
54
readFileSync,
65
rmSync,
@@ -99,17 +98,41 @@ describe("compiled package output", () => {
9998
staticExportNames.forEach((name) => {
10099
expect(compiled).toContain(`exports.${name} =`)
101100
})
101+
102+
const source = readFileSync(
103+
join(process.cwd(), "package", "index.ts"),
104+
"utf8"
105+
)
106+
const shakapackerObject = source.match(
107+
/const shakapacker = \{([\s\S]*?)\n\}/
108+
)[1]
109+
const webpackMergeStaticExportNames = [
110+
"merge",
111+
"mergeWithCustomize",
112+
"mergeWithRules",
113+
"unique"
114+
]
115+
const sourceNonLazyExportNames = [
116+
...Array.from(
117+
shakapackerObject.matchAll(/^\s{2}([A-Za-z]\w*),$/gm),
118+
(match) => match[1]
119+
),
120+
...webpackMergeStaticExportNames
121+
]
122+
expect([...staticExportNames].sort()).toStrictEqual(
123+
sourceNonLazyExportNames.sort()
124+
)
125+
102126
expect(compiled).not.toMatch(/exports\.(baseConfig|rules)\s*=/)
103127
})
104128

105-
// symlinkSync to node_modules/lib requires elevated privileges on Windows
106-
// (EPERM), so the native-ESM consumer specs are skipped there; the
107-
// declaration-emit test above does not symlink and still runs.
129+
// symlinkSync requires elevated privileges on Windows (EPERM), so the
130+
// native-ESM consumer specs are skipped there; the declaration-emit test above
131+
// does not symlink and still runs.
108132
const describeOrSkip = process.platform === "win32" ? describe.skip : describe
109133
const libDir = join(process.cwd(), "lib")
110-
const describeOrSkipLib = existsSync(libDir) ? describeOrSkip : describe.skip
111134

112-
describeOrSkipLib("native ESM consumers", () => {
135+
describeOrSkip("native ESM consumers", () => {
113136
beforeAll(() => {
114137
symlinkSync(
115138
join(process.cwd(), "node_modules"),

0 commit comments

Comments
 (0)