Skip to content

fix: should remain process.env.NODE_ENV as is by default #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion e2e/cases/auto-external/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ test('auto external false should works', async () => {

// dts should bundled
expect(dts.entries.esm).toContain('export declare function oraPromise');

expect(dts.entries.cjs).toContain('export declare function oraPromise');
});

Expand Down
12 changes: 9 additions & 3 deletions e2e/cases/define/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ test('source.define', async () => {
const fixturePath = __dirname;
const { entries } = await buildAndGetResults(fixturePath);

expect(entries.esm).not.toContain('console.info(VERSION)');
expect(entries.esm).toContain('1.0.0');
expect(entries.esm0).not.toContain('console.info(VERSION)');
expect(entries.esm0).toContain('console.info("1.0.0")');
expect(entries.esm0).toContain('console.info(process.env.NODE_ENV)');

expect(entries.esm1).not.toContain('console.info(VERSION)');
expect(entries.esm1).toContain('console.info("1.0.0")');
expect(entries.esm1).toContain('console.info(process.ENV.MY_CUSTOM_ENV)');

expect(entries.cjs).not.toContain('console.info(VERSION)');
expect(entries.cjs).toContain('1.0.0');
expect(entries.cjs).toContain('console.info("1.0.0")');
expect(entries.cjs).toContain('console.info(process.env.NODE_ENV)');
});
43 changes: 39 additions & 4 deletions e2e/cases/define/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,48 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [generateBundleEsmConfig(), generateBundleCjsConfig()],
lib: [
generateBundleEsmConfig({
source: {
define: {
VERSION: JSON.stringify('1.0.0'),
},
},
output: {
distPath: {
root: './dist/esm/0',
},
},
}),
generateBundleEsmConfig({
source: {
define: {
VERSION: JSON.stringify('1.0.0'),
'process.env.NODE_ENV': 'process.ENV.MY_CUSTOM_ENV',
},
},
output: {
distPath: {
root: './dist/esm/1',
},
},
}),
generateBundleCjsConfig({
source: {
define: {
VERSION: JSON.stringify('1.0.0'),
},
},
output: {
distPath: {
root: './dist/cjs/0',
},
},
}),
],
source: {
entry: {
index: './src/index.ts',
},
define: {
VERSION: JSON.stringify('1.0.0'),
},
},
});
1 change: 1 addition & 0 deletions e2e/cases/define/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.info(VERSION);
console.info(process.env.NODE_ENV); // Should remain as is.
13 changes: 10 additions & 3 deletions e2e/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,16 @@ export async function getResults(
}

// Only applied in bundle mode, a shortcut to get single entry result
if (libConfig.bundle !== false && fileSet.length === 1) {
entries[key] = content[fileSet[0]!]!;
entryFiles[key] = fileSet[0]!;
if (libConfig.bundle !== false && fileSet.length) {
let entryFile = '';
if (fileSet.length === 1) {
entryFile = fileSet[0]!;
} else {
entryFile = fileSet.find((file) => file.includes('index'))!;
}

entries[key] = content[entryFile]!;
entryFiles[key] = entryFile;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export async function createConstantRsbuildConfig(): Promise<RsbuildConfig> {
rspack: {
optimization: {
moduleIds: 'named',
nodeEnv: false,
},
experiments: {
rspackFuture: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
},
"optimization": {
"moduleIds": "named",
"nodeEnv": false,
},
"resolve": {
"extensionAlias": {
Expand Down Expand Up @@ -210,6 +211,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
},
"optimization": {
"moduleIds": "named",
"nodeEnv": false,
},
"resolve": {
"extensionAlias": {
Expand Down Expand Up @@ -334,6 +336,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
},
"optimization": {
"moduleIds": "named",
"nodeEnv": false,
},
"resolve": {
"extensionAlias": {
Expand Down
Loading