Skip to content

Commit

Permalink
chore: swtich to rolldown bundling (experimental) (#2067)
Browse files Browse the repository at this point in the history
* chore: swtich to rolldown bundling

* fix

* fix: rolldown errors

* fix: wrong exporting

* fix: output dist files

* fix: generate stub file

* fix: add type definition generating script with oxc-transform

* chore: drop unnecesary scripts

* fix: isolatedDeclaration build errors for oxc

* fix: export lite module for petite-vue-i18n

* fix: update stubs

* fix: update from rollup config

* fix: vue-i18n type generation

* chore: ignore format and lint

* fix: refactor codes

* fix: bundle dts files

* chore: add ci for rolldown build

* fix: dts scripts

* fix: update deps

* chore: disable e2e for rolldown

* chore: refactor rollup building
  • Loading branch information
kazupon authored Jan 6, 2025
1 parent b2ab7fd commit 7eb919e
Show file tree
Hide file tree
Showing 52 changed files with 2,370 additions and 788 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ jobs:
path: packages/*/dist
key: build-vue-i18n-os-${{ matrix.os }}-${{ github.sha }}

build-rolldown:
name: Build with rolldown
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [18]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout codes
uses: actions/checkout@v4

- name: Enable corepack
run: corepack enable

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --no-frozen-lockfile

- name: Build codes
run: |
pnpm build:rolldown --withTypes
- name: Cache dist
uses: actions/cache@v4
with:
path: packages/*/dist
key: build-rolldown-vue-i18n-os-${{ matrix.os }}-${{ github.sha }}

test-unit:
name: Unit test
strategy:
Expand Down Expand Up @@ -147,3 +182,44 @@ jobs:

- name: Run e2e tests
run: pnpm test:e2e

# test-e2e-rolldown:
# name: E2E test for rolldown build

# needs:
# - build-rolldown

# strategy:
# matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]
# node: [18.19, 20, 22]

# runs-on: ${{ matrix.os }}

# steps:
# - name: Checkout codes
# uses: actions/checkout@v4

# - name: Enable corepack
# run: corepack enable

# - name: Setup node
# uses: actions/setup-node@v4
# with:
# node-version: ${{ matrix.node }}
# cache: 'pnpm'

# - name: Install dependencies
# run: pnpm install --no-frozen-lockfile

# - name: Install Playwright
# run: pnpm playwright-core install chromium

# - name: Restore dist cache
# uses: actions/cache@v4
# with:
# path: packages/*/dist
# key: build-rolldown-vue-i18n-os-${{ matrix.os }}-${{ github.sha }}

# - name: Run e2e tests
# run: pnpm test:e2e
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ docs
coverage
tsconfig.json
api-extractor.json
README.md
README.md
temp
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
*
* DEFAULT VALUE: "warning"
*/
"logLevel": "warning",
"logLevel": "none", /* FIXME: Change to "warning" */

/**
* When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md),
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ export default [
'**/test/**',
'**/examples/**',
'shim.d.ts',
'temp/**',
'.eslintcache',
'.eslintrc.cjs',
'packages/*/vite.config.ts',
'packages/*/index.js',
'packages/vue-i18n-core/petite.js',
'docsgen.config.js',
'scripts/api/*.js'
]
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"bench:simple-jit-aot": "node --expose-gc ./benchmark/simple-jit-aot.mjs",
"build": "tsx ./scripts/build.ts",
"build:explorer": "pnpm --filter @intlify/message-format-explorer build",
"build:rolldown": "tsx ./scripts/build-rolldown.ts",
"build:size": "pnpm build && run-p build:size-*",
"build:size-core": "pnpm --filter @intlify/size-check-core build",
"build:size-petite-vue-i18n": "pnpm --filter @intlify/size-check-petite-vue-i18n build",
Expand Down Expand Up @@ -84,16 +85,18 @@
"@eslint/js": "^9.9.1",
"@intlify/core-base": "workspace:*",
"@intlify/message-compiler": "workspace:*",
"@intlify/vue-i18n-core": "workspace:*",
"@microsoft/api-extractor": "7.15.2",
"@rolldown/plugin-node-polyfills": "^1.0.0",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
"@secretlint/secretlint-rule-preset-recommend": "^3.1.0",
"@swc/core": "^1.10.4",
"@textlint-rule/textlint-rule-no-unmatched-pair": "^2.0.0",
"@types/eslint": "^9.6.1",
"@types/js-yaml": "^4.0.5",
"@types/jsdom": "^21.1.1",
"@types/node": "^22.10.3",
"@types/rc": "^1.2.4",
Expand All @@ -106,25 +109,28 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vue": "^9.28.0",
"execa": "^9.3.0",
"fast-glob": "^3.3.3",
"fixpack": "^4.0.0",
"get-port-please": "^3.1.2",
"globals": "^15.9.0",
"globby": "^14.0.1",
"js-yaml": "^4.1.0",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"listhen": "^1.7.2",
"magic-string": "^0.30.17",
"markdown-table": "^3.0.4",
"mitata": "^1.0.20",
"npm-run-all2": "^7.0.0",
"opener": "^1.5.2",
"pathe": "^1.1.2",
"oxc-parser": "^0.44.0",
"oxc-transform": "^0.44.0",
"picocolors": "^1.0.0",
"pkg-pr-new": "^0.0.37",
"playwright-core": "^1.45.3",
"prettier": "^3.3.3",
"rc": "^1.2.8",
"rolldown": "1.0.0-beta.1",
"rollup": "^4.21.2",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-typescript2": "^0.36.0",
Expand All @@ -150,7 +156,7 @@
"trash-cli": "^6.0.0",
"tslib": "^2.6.2",
"tsx": "^4.11.2",
"typescript": "^5.5.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.4.0",
"vitepress": "1.5.0",
"vitest": "^2.1.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export interface CoreInternalContext {
* Intlify core-base version
* @internal
*/
export const VERSION = __VERSION__
export const VERSION: string = __VERSION__

export const NOT_REOSLVED = -1

Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export function datetime<
}

/** @internal */
export const DATETIME_FORMAT_OPTIONS_KEYS = [
export const DATETIME_FORMAT_OPTIONS_KEYS: string[] = [
'localeMatcher',
'weekday',
'era',
Expand Down
8 changes: 6 additions & 2 deletions packages/core-base/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export function initI18nDevTools(
})
}

export const translateDevTools =
export const translateDevTools: ReturnType<typeof createDevToolsHook> =
/* #__PURE__*/ createDevToolsHook('function:translate')

function createDevToolsHook(hook: IntlifyDevToolsHooks) {
function createDevToolsHook(
hook: IntlifyDevToolsHooks
): (
payloads: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks]
) => void | null {
return (payloads: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks]) =>
devtools && devtools.emit(hook, payloads)
}
2 changes: 1 addition & 1 deletion packages/core-base/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { BaseError } from '@intlify/shared'
export interface CoreError extends BaseError {}

export const CoreErrorCodes = {
INVALID_ARGUMENT: COMPILE_ERROR_CODES_EXTEND_POINT, // 17
INVALID_ARGUMENT: COMPILE_ERROR_CODES_EXTEND_POINT as number, // 17
INVALID_DATE_ARGUMENT: 18,
INVALID_ISO_DATE_ARGUMENT: 19,
NOT_SUPPORT_NON_STRING_MESSAGE: 20,
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/fallbacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function getLocale<Messages, Message>(
let _resolveLocale: string

/** @internal */
export function resolveLocale(locale: Locale | LocaleDetector) {
export function resolveLocale(locale: Locale | LocaleDetector): string {
if (isString(locale)) {
return locale
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function formatMessagePart<Message = string>(

const PROPS_TYPE = ['t', 'type']

export function resolveType(node: Node) {
export function resolveType(node: Node): ReturnType<typeof resolveProps> {
return resolveProps<NodeTypes>(node, PROPS_TYPE)
}

Expand Down
12 changes: 4 additions & 8 deletions packages/core-base/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { initFeatureFlags } from './misc'

export {
export { createCompileError } from '@intlify/message-compiler'
export type {
CompileError,
CompileErrorCodes,
createCompileError,
ResourceNode
} from '@intlify/message-compiler'
export * from './compilation'
export * from './context'
export * from './datetime'
export * from './devtools'
export {
CORE_ERROR_CODES_EXTEND_POINT,
CoreError,
CoreErrorCodes,
createCoreError
} from './errors'
export { CORE_ERROR_CODES_EXTEND_POINT, createCoreError } from './errors'
export type { CoreError, CoreErrorCodes } from './errors'
export * from './fallbacker'
export * from './number'
export * from './resolver'
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function number<
}

/** @internal */
export const NUMBER_FORMAT_OPTIONS_KEYS = [
export const NUMBER_FORMAT_OPTIONS_KEYS: string[] = [
'localeMatcher',
'style',
'currency',
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const CoreWarnCodes = {
EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7
} as const

export const CORE_WARN_CODES_EXTEND_POINT = 8
export const CORE_WARN_CODES_EXTEND_POINT: number = 8

export type CoreWarnCodes = (typeof CoreWarnCodes)[keyof typeof CoreWarnCodes]

Expand Down
2 changes: 1 addition & 1 deletion packages/format-explorer/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@ export default {
'editorCursor.foreground': '#AEAFAD',
'editorWhitespace.foreground': '#4B4E55'
}
}
} as const
2 changes: 1 addition & 1 deletion packages/message-compiler/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const CompileErrorCodes = {
// Special value for higher-order compilers to pick up the last code
// to avoid collision of error codes.
// This should always be kept as the last item.
export const COMPILE_ERROR_CODES_EXTEND_POINT = 17
export const COMPILE_ERROR_CODES_EXTEND_POINT: number = 17

export type CompileErrorCodes =
(typeof CompileErrorCodes)[keyof typeof CompileErrorCodes]
Expand Down
2 changes: 1 addition & 1 deletion packages/message-compiler/src/mangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ERROR_DOMAIN = 'minifier'

/* eslint-disable @typescript-eslint/no-explicit-any */

export function mangle(node: Node) {
export function mangle(node: Node): void {
node.t = node.type

switch (node.type) {
Expand Down
6 changes: 4 additions & 2 deletions packages/message-compiler/src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export interface Scanner {
export const CHAR_SP = ' '
export const CHAR_CR = '\r'
export const CHAR_LF = '\n'
export const CHAR_LS = String.fromCharCode(0x2028)
export const CHAR_PS = String.fromCharCode(0x2029)
export const CHAR_LS: ReturnType<typeof String.fromCharCode> =
String.fromCharCode(0x2028)
export const CHAR_PS: ReturnType<typeof String.fromCharCode> =
String.fromCharCode(0x2029)

export function createScanner(str: string): Scanner {
const _buf = str
Expand Down
1 change: 1 addition & 0 deletions packages/petite-vue-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"@intlify/core-base": "workspace:*",
"@intlify/shared": "workspace:*",
"@intlify/vue-i18n-core": "workspace:*",
"@vue/devtools-api": "^6.5.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 7eb919e

Please sign in to comment.