Skip to content

Commit a6ddd4d

Browse files
committed
win
1 parent 4a7c331 commit a6ddd4d

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

packages/core/src/plugins/EntryChunkPlugin.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class EntryChunkPlugin {
7474
encoding: 'utf-8',
7575
});
7676

77+
console.log('🥵', content.includes('\n'), content.includes('\r\n'));
78+
7779
// Shebang
7880
if (content.startsWith(SHEBANG_PREFIX)) {
7981
const shebangMatch = matchFirstLine(content, SHEBANG_REGEX);
@@ -118,6 +120,12 @@ class EntryChunkPlugin {
118120
for (const name of chunkAsset) {
119121
compilation.updateAsset(name, (old) => {
120122
const oldSource = old.source().toString();
123+
console.log(
124+
'🤡',
125+
oldSource.includes('\n'),
126+
oldSource.includes('\r\n'),
127+
);
128+
121129
const replaceSource = new rspack.sources.ReplaceSource(old);
122130
if (
123131
oldSource.startsWith('use strict;') ||
@@ -126,7 +134,7 @@ class EntryChunkPlugin {
126134
replaceSource.replace(
127135
0,
128136
11, // 'use strict;'.length,
129-
`"use strict";${os.EOL}${importMetaUrlShim}`,
137+
`"use strict";\n${importMetaUrlShim}`,
130138
);
131139
} else {
132140
replaceSource.insert(0, importMetaUrlShim);
@@ -154,13 +162,13 @@ class EntryChunkPlugin {
154162
const replaceSource = new rspack.sources.ReplaceSource(old);
155163
// Shebang
156164
if (shebangValue) {
157-
replaceSource.insert(0, `${shebangValue}${os.EOL}`);
165+
replaceSource.insert(0, `${shebangValue}\n`);
158166
this.shebangInjectedAssets.add(name);
159167
}
160168

161169
// React directives
162170
if (reactDirectiveValue) {
163-
replaceSource.insert(0, `${reactDirectiveValue}${os.EOL}`);
171+
replaceSource.insert(0, `${reactDirectiveValue}\n`);
164172
}
165173

166174
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ 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+
console.log('🥺', cjsCode.includes('\n'), cjsCode.includes('\r\n'));
99+
expect(
100+
cjsCode.startsWith(
101+
`"use strict";\nconst __rslib_import_meta_url__ = /*#__PURE__*/ function() {`,
102+
),
103+
).toBe(true);
102104
});
103105

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

0 commit comments

Comments
 (0)