Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/reusable-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
matrix:
node: ${{ fromJSON(
inputs.target == 'wasm32-wasip1-threads'&& '[24]'
|| contains(inputs.target, 'linux') && '[18, 20, 22]'
|| contains(inputs.target, 'linux') && '[20, 22, 24]'
|| '[22]') }}
name: Test Node ${{ matrix.node }}
defaults:
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
- name: Pnpm Install
uses: ./.github/actions/pnpm/install-dependencies
with:
save-if: ${{ github.ref_name == 'main' && matrix.node == '18' }}
save-if: ${{ github.ref_name == 'main' && matrix.node == '20' }}

### x86_64-unknown-linux-gnu
- name: Test x86_64-unknown-linux-gnu
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"cross-env": "^10.1.0",
"husky": "^9.1.7",
"is-ci": "4.1.0",
"@rstest/core": "^0.7.8",
"@rstest/core": "^0.7.9",
"lint-staged": "^16.2.7",
"prettier": "3.7.4",
"prettier-2": "npm:prettier@2.8.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-rspack/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [{ format: 'esm', syntax: ['node 18.12'] }],
lib: [{ format: 'esm', syntax: ['es2023'] }],
});
1 change: 0 additions & 1 deletion packages/create-rspack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"module": "NodeNext",
"outDir": "dist",
"rootDir": "src"
}
Expand Down
5 changes: 2 additions & 3 deletions packages/rspack-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"license": "MIT",
"description": "Rspack for running in the browser. This is still in early stage and may not follow the semver.",
"type": "module",
"main": "./dist/index.mjs",
"types": "./dist/browser/index.d.ts",
"publishConfig": {
"access": "public",
Expand All @@ -14,9 +13,9 @@
"exports": {
".": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/index.mjs"
"default": "./dist/index.js"
},
"./wasi-worker-browser.mjs": "./wasi-worker-browser.mjs",
"./wasi-worker-browser.js": "./wasi-worker-browser.js",
"./package.json": "./package.json"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-cli/bin/rspack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
const nodeModule = require('node:module');
import nodeModule from 'node:module';

// enable on-disk code caching of all modules loaded by Node.js
// requires Nodejs >= 22.8.0
Expand All @@ -15,7 +15,7 @@ if (enableCompileCache) {
// make it easier to identify the process via activity monitor or other tools
process.title = 'rspack-node';

const { RspackCLI } = require('../dist/index');
import { RspackCLI } from '../dist/index.js';

async function runCLI() {
const cli = new RspackCLI();
Expand Down
5 changes: 2 additions & 3 deletions packages/rspack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
"directory": "packages/rspack-cli"
},
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"rspack": "./bin/rspack.js"
Expand Down
13 changes: 7 additions & 6 deletions packages/rspack-cli/rslib.config.mts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { createRequire } from 'node:module';
import { defineConfig } from '@rslib/core';

const require = createRequire(import.meta.url);
import packageJson from './package.json' with { type: 'json' };

export default defineConfig({
lib: [
{ format: 'cjs', syntax: ['node 18.12'], dts: { bundle: false } },
{ format: 'esm', syntax: ['node 18.12'] },
{
format: 'esm',
syntax: ['es2023'],
dts: true,
},
],
source: {
tsconfigPath: './tsconfig.build.json',
define: {
RSPACK_CLI_VERSION: JSON.stringify(require('./package.json').version),
RSPACK_CLI_VERSION: JSON.stringify(packageJson.version),
},
},
});
2 changes: 1 addition & 1 deletion packages/rspack-cli/rstest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig({
testEnvironment: 'node',
globals: true,
testTimeout: process.env.CI ? 200000 : 30000,
include: ['tests/**/*.test.ts', 'tests/**/*.test.js'],
include: ['tests/**/*.test.{ts,js,cts}'],
source: {
tsconfigPath: 'tests/tsconfig.json',
},
Expand Down
3 changes: 3 additions & 0 deletions packages/rspack-cli/src/utils/crossImport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
import { isEsmFile } from './isEsmFile';

const require = createRequire(import.meta.url);

export const crossImport = async <T = any>(path: string): Promise<T> => {
if (isEsmFile(path)) {
const url = pathToFileURL(path).href;
Expand Down
3 changes: 3 additions & 0 deletions packages/rspack-cli/src/utils/loadConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs';
import { createRequire } from 'node:module';
import path from 'node:path';
import type { MultiRspackOptions, RspackOptions } from '@rspack/core';
import { addHook } from 'pirates';
Expand All @@ -9,6 +10,8 @@ import isTsFile, { TS_EXTENSION } from './isTsFile';
import type { CommonOptions } from './options';
import { rspack } from './rspackCore';

const require = createRequire(import.meta.url);

const injectInlineSourceMap = ({
code,
map,
Expand Down
13 changes: 1 addition & 12 deletions packages/rspack-cli/src/utils/rspackCore.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import { createRequire } from 'node:module';

/**
* Currently, Rspack only provides a CJS bundle, so we use require to load it
* for better startup performance.
* https://github.com/nodejs/node/issues/59913
*/
// @ts-expect-error can be removed after add `type: "module"` to package.json
const require = createRequire(import.meta.url);
const rspack: (typeof import('@rspack/core'))['rspack'] = require('@rspack/core');

export { rspack };
export { rspack } from '@rspack/core';
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import assert from 'node:assert';

type IsFunction<T> = T extends (...args: any[]) => any ? true : false;

// not real Node.js behavior
// https://github.com/web-infra-dev/rspack/issues/8095
describe.concurrent(
'js-api-type should be correct when requiring from @rspack/core',
() => {
it('cjs default require', async () => {
// const rspack = require('@rspack/core')
type Truthy = IsFunction<typeof rspackCjsDefaultRequire>;
const truthy: Truthy = true;
truthy;
assert(rspackCjsDefaultRequire.BannerPlugin);
assert(typeof rspackCjsDefaultRequire === 'function');
const compiler = rspackCjsDefaultRequire({});
assert(typeof rspackCjsDefaultRequire === 'object');
const compiler = rspackCjsDefaultRequire.default({});
assert(compiler);
});

it('cjs named require', async () => {
// const { rspack } = require('@rspack/core')
type Truthy = IsFunction<typeof rspackCjsNamedRequire>;
const truthy: Truthy = true;
truthy;
Expand All @@ -29,9 +32,13 @@ describe.concurrent(
assert(compiler);
});

it('rspack.default should not exist in cjs require', async () => {
it('rspack.default', async () => {
// const { rspack } = require('@rspack/core')
// rspack.default should be undefined
assert(!(rspackCjsNamedRequire as any).default);
assert(!(rspackCjsDefaultRequire as any).default);
// const rspack = require('@rspack/core')
// rspack.default should be defined
assert(!!(rspackCjsDefaultRequire as any).default);
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import rspackEsmDefaultImport, {

type IsFunction<T> = T extends (...args: any[]) => any ? true : false;

// not real Node.js behavior
// https://github.com/web-infra-dev/rspack/issues/8095
describe.concurrent(
'js-api-type should be correct when importing from @rspack/core',
() => {
it('esm default import', async () => {
// rspack has no default export now
type Falsy = IsFunction<typeof rspackEsmDefaultImport>;
const falsy: Falsy = false;
falsy;
assert(rspackEsmDefaultImport);
assert(typeof rspackEsmDefaultImport === 'function');
assert(rspackEsmDefaultImport.BannerPlugin);
});

Expand Down
3 changes: 3 additions & 0 deletions packages/rspack-cli/tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
4 changes: 3 additions & 1 deletion packages/rspack-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"include": ["src"],
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
"rootDir": "src",
"module": "ES2022",
"moduleResolution": "bundler"
},
"references": [
{
Expand Down
4 changes: 4 additions & 0 deletions packages/rspack-test-tools/src/helper/expect/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const placeholderSerializer = createSnapshotSerializer({
match: __RSPACK_PATH__,
mark: 'rspack_root',
},
{
match: /<ROOT>\/packages\/rspack/g,
mark: 'rspack_root',
},
{
match: /:\d+:\d+-\d+:\d+/g,
mark: 'line_col_range',
Expand Down
Loading
Loading