-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add `platform` config - auto externalize node built-in modules when platform is `node`
- Loading branch information
Showing
22 changed files
with
457 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
# Modern.js Module tests coverage | ||
|
||
Rslib will try to cover the common scenarios in the [integration test cases of Modern.js Module](https://github.com/web-infra-dev/modern.js/tree/main/tests/integration/module). This document is used to record the coverage situation. The supported types are divided into three types: "fully supported", "not supported, but planned to support" and "not supported, not planned to support". | ||
Rslib will try to cover the common scenarios in the [integration test cases of Modern.js Module](https://github.com/web-infra-dev/modern.js/tree/main/tests/integration/module). This document is used to record the coverage situation. The supported types are divided into three types: "fully supported", "Partial supported", "not supported, but planned to support" and "not supported, not planned to support". | ||
|
||
## build | ||
|
||
| Supported | Will support | Will not support | | ||
| --------- | ------------ | ---------------- | | ||
| 🟢 | 🟡 | ⚪️ | | ||
| Supported | Partial supported | Will support | Will not support | | ||
| --------- | ----------------- | ------------ | ---------------- | | ||
| 🟢 | 🟡 | ⚪️ | ⚫️ | | ||
|
||
| Feature | Status | Note | | ||
| --------------- | ------ | ---- | | ||
| alias | 🟢 | | | ||
| asset | 🟡 | | | ||
| autoExtension | 🟡 | | | ||
| autoExternal | 🟡 | | | ||
| banner-footer | 🟡 | | | ||
| buildType | 🟡 | | | ||
| copy | 🟡 | | | ||
| decorator | 🟡 | | | ||
| define | 🟢 | | | ||
| dts | 🟡 | | | ||
| dts-composite | 🟡 | | | ||
| esbuildOptions | 🟡 | | | ||
| externals | 🟡 | | | ||
| format | 🟡 | | | ||
| input | 🟡 | | | ||
| jsx | 🟡 | | | ||
| metafile | 🟡 | | | ||
| minify | 🟡 | | | ||
| platform | 🟡 | | | ||
| redirect | 🟡 | | | ||
| resolve | 🟡 | | | ||
| shims | 🟡 | | | ||
| sideEffects | 🟡 | | | ||
| sourceDir | 🟡 | | | ||
| sourceMap | 🟡 | | | ||
| splitting | 🟡 | | | ||
| style | 🟡 | | | ||
| target | 🟡 | | | ||
| transformImport | 🟡 | | | ||
| transformLodash | 🟡 | | | ||
| tsconfig | 🟡 | | | ||
| tsconfigExtends | 🟡 | | | ||
| umdGlobals | 🟡 | | | ||
| umdModuleName | 🟡 | | | ||
| Feature | Status | Note | | ||
| --------------- | ------ | ----------------------------------------------------------------------------------------------------------------------- | | ||
| alias | 🟢 | | | ||
| asset | ⚪️ | | | ||
| autoExtension | ⚪️ | | | ||
| autoExternal | ⚪️ | | | ||
| banner-footer | ⚪️ | | | ||
| buildType | ⚪️ | | | ||
| copy | ⚪️ | | | ||
| decorator | ⚪️ | | | ||
| define | 🟢 | | | ||
| dts | ⚪️ | | | ||
| dts-composite | ⚪️ | | | ||
| esbuildOptions | ⚪️ | | | ||
| externals | 🟡 | Support auto externalize Node.js built-in modules.<br />Should also support auto externalize `devDep && !peerDep` deps. | | ||
| format | ⚪️ | | | ||
| input | ⚪️ | | | ||
| jsx | ⚪️ | | | ||
| metafile | ⚪️ | | | ||
| minify | ⚪️ | | | ||
| platform | ⚪️ | | | ||
| redirect | ⚪️ | | | ||
| resolve | ⚪️ | | | ||
| shims | ⚪️ | | | ||
| sideEffects | ⚪️ | | | ||
| sourceDir | ⚪️ | | | ||
| sourceMap | ⚪️ | | | ||
| splitting | ⚪️ | | | ||
| style | ⚪️ | | | ||
| target | ⚪️ | | | ||
| transformImport | ⚪️ | | | ||
| transformLodash | ⚪️ | | | ||
| tsconfig | ⚪️ | | | ||
| tsconfigExtends | ⚪️ | | | ||
| umdGlobals | ⚪️ | | | ||
| umdModuleName | ⚪️ | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,46 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`alias in ts 1`] = ` | ||
"var __webpack_exports__ = {}; | ||
"var __webpack_modules__ = ({}); | ||
/************************************************************************/ | ||
// The module cache | ||
var __webpack_module_cache__ = {}; | ||
// The require function | ||
function __webpack_require__(moduleId) { | ||
// Check if module is in cache | ||
var cachedModule = __webpack_module_cache__[moduleId]; | ||
if (cachedModule !== undefined) { | ||
return cachedModule.exports; | ||
} | ||
// Create a new module (and put it into the cache) | ||
var module = (__webpack_module_cache__[moduleId] = { | ||
exports: {} | ||
}); | ||
// Execute the module function | ||
__webpack_modules__[moduleId](module, module.exports, __webpack_require__); | ||
// Return the exports of the module | ||
return module.exports; | ||
} | ||
/************************************************************************/ | ||
// webpack/runtime/rspack_version | ||
(() => { | ||
__webpack_require__.rv = function () { | ||
return "1.0.0-canary-0b368b6-20240704171208"; | ||
}; | ||
})(); | ||
// webpack/runtime/rspack_unique_id | ||
(() => { | ||
__webpack_require__.ruid = "[email protected]"; | ||
})(); | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
;// CONCATENATED MODULE: ./e2e/cases/alias/ts/src/a.ts | ||
const a = 'hello world'; | ||
|
@@ -17,17 +56,7 @@ export { a }; | |
exports[`alias in ts 2`] = ` | ||
"(() => { // webpackBootstrap | ||
"use strict"; | ||
var __webpack_modules__ = ({ | ||
"522": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { | ||
__webpack_require__.d(__webpack_exports__, { | ||
a: function() { return a; } | ||
}); | ||
const a = 'hello world'; | ||
}), | ||
}); | ||
var __webpack_modules__ = ({}); | ||
/************************************************************************/ | ||
// The module cache | ||
var __webpack_module_cache__ = {}; | ||
|
@@ -53,40 +82,27 @@ return module.exports; | |
} | ||
/************************************************************************/ | ||
// webpack/runtime/define_property_getters | ||
(() => { | ||
__webpack_require__.d = function(exports, definition) { | ||
for(var key in definition) { | ||
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
} | ||
} | ||
}; | ||
})(); | ||
// webpack/runtime/has_own_property | ||
// webpack/runtime/rspack_version | ||
(() => { | ||
__webpack_require__.o = function (obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
__webpack_require__.rv = function () { | ||
return "1.0.0-canary-0b368b6-20240704171208"; | ||
}; | ||
})(); | ||
// webpack/runtime/make_namespace_object | ||
// webpack/runtime/rspack_unique_id | ||
(() => { | ||
// define __esModule on exports | ||
__webpack_require__.r = function(exports) { | ||
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}; | ||
__webpack_require__.ruid = "[email protected]"; | ||
})(); | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(522); | ||
console.info(_src_a__WEBPACK_IMPORTED_MODULE_0__.a); | ||
;// CONCATENATED MODULE: ./e2e/cases/alias/ts/src/a.ts | ||
const a = 'hello world'; | ||
;// CONCATENATED MODULE: ./e2e/cases/alias/ts/src/index.ts | ||
console.info(a); | ||
var __webpack_export_target__ = exports; | ||
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
import { join } from 'node:path'; | ||
import { build } from '@rslib/core'; | ||
import { expect, test } from 'vitest'; | ||
import { getEntryJsResults } from '#shared'; | ||
import { loadConfig } from '../../../packages/core/src/config'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('alias in js', async () => { | ||
delete process.env.NODE_ENV; | ||
|
||
const fixturePath = join(__dirname, 'js'); | ||
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); | ||
await build(rslibConfig); | ||
const results = await getEntryJsResults(rslibConfig); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(results.esm).toContain('hello world'); | ||
expect(results.cjs).toContain('hello world'); | ||
expect(entries.esm).toContain('hello world'); | ||
expect(entries.cjs).toContain('hello world'); | ||
}); | ||
|
||
test('alias in ts', async () => { | ||
delete process.env.NODE_ENV; | ||
|
||
const fixturePath = join(__dirname, 'ts'); | ||
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); | ||
await build(rslibConfig); | ||
const results = await getEntryJsResults(rslibConfig); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(results.esm).toContain('hello world'); | ||
expect(results.cjs).toContain('hello world'); | ||
expect(entries.esm).toContain('hello world'); | ||
expect(entries.cjs).toContain('hello world'); | ||
|
||
// simple artifacts check | ||
expect(results.esm).toMatchSnapshot(); | ||
expect(results.cjs).toMatchSnapshot(); | ||
expect(entries.esm).toMatchSnapshot(); | ||
expect(entries.cjs).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
import { join } from 'node:path'; | ||
import { build } from '@rslib/core'; | ||
import { expect, test } from 'vitest'; | ||
import { getEntryJsResults } from '#shared'; | ||
import { loadConfig } from '../../../packages/core/src/config'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('define in js', async () => { | ||
delete process.env.NODE_ENV; | ||
|
||
const fixturePath = join(__dirname, 'js'); | ||
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); | ||
await build(rslibConfig); | ||
const results = await getEntryJsResults(rslibConfig); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
// TODO: remove js/ts dir in cases `define` and `alias` | ||
// supersede with a complex js/ts combined case | ||
expect(entries.esm).not.toContain('console.info(VERSION)'); | ||
expect(entries.esm).toContain('1.0.0'); | ||
|
||
expect(results.esm).not.toContain('console.info(VERSION)'); | ||
expect(results.esm).toContain('1.0.0'); | ||
expect(results.cjs).not.toContain('console.info(VERSION)'); | ||
expect(results.cjs).toContain('1.0.0'); | ||
expect(entries.cjs).not.toContain('console.info(VERSION)'); | ||
expect(entries.cjs).toContain('1.0.0'); | ||
}); | ||
|
||
test('define in ts', async () => { | ||
delete process.env.NODE_ENV; | ||
|
||
const fixturePath = join(__dirname, 'ts'); | ||
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); | ||
await build(rslibConfig); | ||
const results = await getEntryJsResults(rslibConfig); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(entries.esm).not.toContain('console.info(VERSION)'); | ||
expect(entries.esm).toContain('1.0.0'); | ||
|
||
expect(results.esm).not.toContain('console.info(VERSION)'); | ||
expect(results.esm).toContain('1.0.0'); | ||
expect(results.cjs).not.toContain('console.info(VERSION)'); | ||
expect(results.cjs).toContain('1.0.0'); | ||
expect(entries.cjs).not.toContain('console.info(VERSION)'); | ||
expect(entries.cjs).toContain('1.0.0'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { join } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('should fail when platform is not "node"', async () => { | ||
delete process.env.NODE_ENV; | ||
|
||
const fixturePath = join(__dirname); | ||
const build = buildAndGetResults(fixturePath); | ||
await expect(build).rejects.toThrowError('Rspack build failed!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { join } from 'node:path'; | ||
import { defineConfig } from '@rslib/core'; | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; | ||
|
||
export default defineConfig({ | ||
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], | ||
source: { | ||
entry: { | ||
main: join(__dirname, 'src/index.ts'), | ||
}, | ||
}, | ||
output: { | ||
externals: { react: 'react' }, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import fs from 'fs'; // Should not be resolved when target is not "node" | ||
import assert from 'node:assert'; // Should not be resolved when target is not "node" | ||
|
||
export const foo = () => { | ||
assert(fs, 'fs exists'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { join } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('auto externalize Node.js built-in modules when platform is "node"', async () => { | ||
delete process.env.NODE_ENV; | ||
|
||
const fixturePath = join(__dirname); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
for (const external of [ | ||
'import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs"', | ||
'import * as __WEBPACK_EXTERNAL_MODULE_node_assert__ from "node:assert"', | ||
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"', | ||
]) { | ||
expect(entries.esm).toContain(external); | ||
} | ||
|
||
for (const external of [ | ||
'var external_fs_namespaceObject = require("fs");', | ||
'var external_node_assert_namespaceObject = require("node:assert");', | ||
'var external_react_namespaceObject = require("react");', | ||
]) { | ||
expect(entries.cjs).toContain(external); | ||
} | ||
}); |
Oops, something went wrong.