Skip to content

Commit aef2bb1

Browse files
committed
win
1 parent 4a7c331 commit aef2bb1

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

packages/core/src/plugins/EntryChunkPlugin.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class EntryChunkPlugin {
118118
for (const name of chunkAsset) {
119119
compilation.updateAsset(name, (old) => {
120120
const oldSource = old.source().toString();
121+
console.log(
122+
'🤡',
123+
oldSource.includes('\n'),
124+
oldSource.includes('\r\n'),
125+
);
126+
121127
const replaceSource = new rspack.sources.ReplaceSource(old);
122128
if (
123129
oldSource.startsWith('use strict;') ||
@@ -126,7 +132,7 @@ class EntryChunkPlugin {
126132
replaceSource.replace(
127133
0,
128134
11, // 'use strict;'.length,
129-
`"use strict";${os.EOL}${importMetaUrlShim}`,
135+
`"use strict";\n${importMetaUrlShim}`,
130136
);
131137
} else {
132138
replaceSource.insert(0, importMetaUrlShim);
@@ -154,13 +160,13 @@ class EntryChunkPlugin {
154160
const replaceSource = new rspack.sources.ReplaceSource(old);
155161
// Shebang
156162
if (shebangValue) {
157-
replaceSource.insert(0, `${shebangValue}${os.EOL}`);
163+
replaceSource.insert(0, `${shebangValue}\n`);
158164
this.shebangInjectedAssets.add(name);
159165
}
160166

161167
// React directives
162168
if (reactDirectiveValue) {
163-
replaceSource.insert(0, `${reactDirectiveValue}${os.EOL}`);
169+
replaceSource.insert(0, `${reactDirectiveValue}\n`);
164170
}
165171

166172
return replaceSource;

packages/core/src/plugins/entryModuleLoader.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const loader: LoaderDefinition = function loader(source) {
1010
let result = source;
1111

1212
if (this.resourceQuery === `?${RSLIB_ENTRY_QUERY}`) {
13-
const [firstLine1, ...rest1] = result.split(os.EOL).slice(1);
13+
console.log('👝', source.includes('\n'), source.includes('\r\n'));
14+
const [firstLine1, ...rest1] = result.split(os.EOL);
15+
1416
if (SHEBANG_REGEX.test(firstLine1!)) {
1517
result = rest1.join(os.EOL);
1618
}

pnpm-lock.yaml

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/shims/index.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ describe('CJS shims', () => {
9595
const fileUrl = pathToFileURL(entryFiles.cjs).href;
9696
expect(importMetaUrl).toBe(fileUrl);
9797
expect(requiredModule).toBe('ok');
98-
expect(cjsCode.startsWith('"use strict"')).toBe(true);
99-
expect(cjsCode).toContain(
100-
'const __rslib_import_meta_url__ = /*#__PURE__*/ function() {',
101-
);
98+
expect(
99+
cjsCode.startsWith(
100+
`"use strict";\nconst __rslib_import_meta_url__ = /*#__PURE__*/ function() {`,
101+
),
102+
).toBe(true);
102103
});
103104

104105
test('ESM should not be affected by CJS shims configuration', async () => {

0 commit comments

Comments
 (0)