Skip to content
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
8 changes: 2 additions & 6 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
DEFAULT_CONFIG_NAME,
DTS_EXTENSIONS_PATTERN,
JS_EXTENSIONS_PATTERN,
RSLIB_ENTRY_QUERY,
SWC_HELPERS,
} from './constant';
import {
Expand Down Expand Up @@ -940,9 +939,6 @@ const traverseEntryQuery = (
return newEntry;
};

export const appendEntryQuery = (entries: RsbuildConfigEntry): RsbuildEntry =>
traverseEntryQuery(entries, (item) => `${item}?${RSLIB_ENTRY_QUERY}`);

export const resolveEntryPath = (
entries: RsbuildConfigEntry,
root: string,
Expand Down Expand Up @@ -1020,7 +1016,7 @@ const composeEntryConfig = async (
return {
entryConfig: {
source: {
entry: appendEntryQuery(resolveEntryPath(entries, root)),
entry: resolveEntryPath(entries, root),
},
},
outBase: null,
Expand Down Expand Up @@ -1126,7 +1122,7 @@ const composeEntryConfig = async (
rspack: {
entry: async () => {
const { resolvedEntries } = await scanGlobEntries(false);
return appendEntryQuery(resolvedEntries);
return resolvedEntries;
},
},
},
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const DEFAULT_CONFIG_EXTENSIONS = [
] as const;

export const SWC_HELPERS = '@swc/helpers';
export const RSLIB_ENTRY_QUERY = '__rslib_entry__';
export const SHEBANG_PREFIX = '#!';
export const SHEBANG_REGEX: RegExp = /#!.*[\s\n\r]*$/;
export const REACT_DIRECTIVE_REGEX: RegExp =
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/plugins/EntryChunkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ const entryModuleLoaderRsbuildPlugin = (): RsbuildPlugin => ({
setup(api) {
api.modifyBundlerChain((config, { CHAIN_ID }) => {
config.module
.rule(CHAIN_ID.RULE.JS)
.rule(`Rslib:${CHAIN_ID.RULE.JS}-entry-loader`)
.test(config.module.rule(CHAIN_ID.RULE.JS).get('test'))
.issuer(/^$/)
.use(LOADER_NAME)
.loader(require.resolve('./entryModuleLoader.js'));
});
Expand Down
22 changes: 8 additions & 14 deletions packages/core/src/plugins/entryModuleLoader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { Rspack } from '@rsbuild/core';
import {
REACT_DIRECTIVE_REGEX,
RSLIB_ENTRY_QUERY,
SHEBANG_REGEX,
} from '../constant';
import { REACT_DIRECTIVE_REGEX, SHEBANG_REGEX } from '../constant';

function splitFromFirstLine(text: string): [string, string] {
const match = text.match(/(\r\n|\n)/);
Expand All @@ -17,17 +13,15 @@ function splitFromFirstLine(text: string): [string, string] {
const loader: Rspack.LoaderDefinition = function loader(source) {
let result = source;

if (this.resourceQuery === `?${RSLIB_ENTRY_QUERY}`) {
const [firstLine1, rest] = splitFromFirstLine(result);
const [firstLine1, rest] = splitFromFirstLine(result);

if (SHEBANG_REGEX.test(firstLine1)) {
result = rest;
}
if (SHEBANG_REGEX.test(firstLine1)) {
result = rest;
}

const [firstLine2, rest2] = splitFromFirstLine(result);
if (REACT_DIRECTIVE_REGEX.test(firstLine2)) {
result = rest2;
}
const [firstLine2, rest2] = splitFromFirstLine(result);
if (REACT_DIRECTIVE_REGEX.test(firstLine2)) {
result = rest2;
}

return result;
Expand Down
110 changes: 0 additions & 110 deletions packages/core/tests/entry.test.ts

This file was deleted.

11 changes: 4 additions & 7 deletions packages/plugin-dts/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,10 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
declarationDir!,
relativePath,
basename(entrySourcePath),
)
// Remove query in file path, such as RSLIB_ENTRY_QUERY.
.replace(/\?.*$/, '')
.replace(
/\.(js|mjs|jsx|ts|mts|tsx|cjs|cts|cjsx|ctsx|mjsx|mtsx)$/,
'.d.ts',
);
).replace(
/\.(js|mjs|jsx|ts|mts|tsx|cjs|cts|cjsx|ctsx|mjsx|mtsx)$/,
'.d.ts',
);
return { name: entryName, path: newPath };
})
.filter(Boolean) as Required<DtsEntry>[];
Expand Down
32 changes: 16 additions & 16 deletions tests/integration/asset/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ console.log(draft_namespaceObject);
`;

exports[`use asset/source 2`] = `
"const draft_rslib_entry_namespaceObject = "this is a txt file\\nthis is a txt file\\n";
export { draft_rslib_entry_namespaceObject as default };
"const draft_namespaceObject = "this is a txt file\\nthis is a txt file\\n";
export { draft_namespaceObject as default };
"
`;

Expand All @@ -19,8 +19,8 @@ console.log(draft_namespaceObject);
`;

exports[`use source.assetInclude 2`] = `
"import draft_rslib_entry_namespaceObject from "../static/assets/draft.txt";
export { draft_rslib_entry_namespaceObject as default };
"import draft_namespaceObject from "../static/assets/draft.txt";
export { draft_namespaceObject as default };
"
`;

Expand Down Expand Up @@ -49,8 +49,8 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
]
})
});
const logo_rslib_entry_ = __rslib_svgr_url__0__;
export { SvgLogo as ReactComponent, logo_rslib_entry_ as default };
const logo = __rslib_svgr_url__0__;
export { SvgLogo as ReactComponent, logo as default };
"
`;

Expand Down Expand Up @@ -81,7 +81,7 @@ var __webpack_require__ = {};
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
default: ()=>logo_rslib_entry_,
default: ()=>logo,
ReactComponent: ()=>SvgLogo
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
Expand All @@ -107,7 +107,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg
]
})
});
const logo_rslib_entry_ = require("../static/svg/logo.svg");
const logo = require("../static/svg/logo.svg");
exports.ReactComponent = __webpack_exports__.ReactComponent;
exports["default"] = __webpack_exports__["default"];
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
Expand Down Expand Up @@ -144,8 +144,8 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_r
]
})
});
const logo_rslib_entry_ = SvgLogo;
export { logo_rslib_entry_ as default };
const logo = SvgLogo;
export { logo as default };
"
`;

Expand Down Expand Up @@ -176,7 +176,7 @@ var __webpack_require__ = {};
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
default: ()=>logo_rslib_entry_
default: ()=>logo
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
Expand All @@ -201,7 +201,7 @@ const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("svg
]
})
});
const logo_rslib_entry_ = SvgLogo;
const logo = SvgLogo;
exports["default"] = __webpack_exports__["default"];
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"default"
Expand All @@ -213,15 +213,15 @@ Object.defineProperty(exports, '__esModule', {
`;

exports[`use svgr > should only contain url default export 1`] = `
"import logo2_rslib_entry_namespaceObject from "../static/svg/logo2.svg";
export { logo2_rslib_entry_namespaceObject as default };
"import logo2_namespaceObject from "../static/svg/logo2.svg";
export { logo2_namespaceObject as default };
"
`;

exports[`use svgr > should only contain url default export 2`] = `
""use strict";
var __webpack_modules__ = {
"./src/assets/logo2.svg?__rslib_entry__": function(module) {
"./src/assets/logo2.svg": function(module) {
module.exports = require("../static/svg/logo2.svg");
}
};
Expand All @@ -235,7 +235,7 @@ function __webpack_require__(moduleId) {
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
return module.exports;
}
var __webpack_exports__ = __webpack_require__("./src/assets/logo2.svg?__rslib_entry__");
var __webpack_exports__ = __webpack_require__("./src/assets/logo2.svg");
exports["default"] = __webpack_exports__["default"];
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"default"
Expand Down
Loading
Loading