Skip to content

Commit

Permalink
feat!: move packages to ESM first (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Nov 16, 2024
1 parent 1e3abe8 commit 27ec73f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/bundle-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@intlify/bundle-utils",
"type": "module",
"description": "Bundle utilities for Intlify project",
"version": "9.0.0",
"author": {
Expand Down Expand Up @@ -47,7 +48,6 @@
"types": "lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.mjs",
"require": "./lib/index.cjs"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/bundle-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "es2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"lib": ["esnext"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down
29 changes: 28 additions & 1 deletion packages/unplugin-vue-i18n/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { readFile, rm, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import { defineBuildConfig } from 'unbuild'

const lib = fileURLToPath(new URL('./lib', import.meta.url))

export default defineBuildConfig({
declaration: true,
outDir: 'lib',
Expand All @@ -24,5 +29,27 @@ export default defineBuildConfig({
rollup: {
emitCJS: true
},
externals: ['vite', 'webpack']
externals: ['vite', 'webpack'],
hooks: {
'build:done': async () => {
await Promise.all([
rm(resolve(lib, 'types.cjs')),
rm(resolve(lib, 'types.mjs')),
...['vite', 'webpack'].map(async name => {
for (const ext of ['d.ts', 'd.cts']) {
const path = resolve(lib, `${name}.${ext}`)
const content = await readFile(path, 'utf-8')
await writeFile(
path,
content.replace(
`export { ${name} as default };`,
`export = ${name};`
),
{ encoding: 'utf-8' }
)
}
})
])
}
}
})
26 changes: 15 additions & 11 deletions packages/unplugin-vue-i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@intlify/unplugin-vue-i18n",
"type": "module",
"version": "5.3.1",
"description": "unplugin for Vue I18n",
"author": {
Expand Down Expand Up @@ -41,7 +42,8 @@
"vue": "^3.4"
},
"devDependencies": {
"unbuild": "^2.0.0"
"unbuild": "^2.0.0",
"@types/node": "^20.14.8"
},
"engines": {
"node": ">= 18"
Expand All @@ -67,22 +69,24 @@
"types": "./index.d.ts",
"exports": {
".": {
"types": "./index.d.ts",
"require": "./lib/index.cjs",
"import": "./lib/index.mjs"
"import": "./lib/index.mjs",
"require": "./lib/index.cjs"
},
"./vite": {
"types": "./vite.d.ts",
"require": "./lib/vite.cjs",
"import": "./lib/vite.mjs"
"import": "./lib/vite.mjs",
"require": "./lib/vite.cjs"
},
"./webpack": {
"types": "./webpack.d.ts",
"require": "./lib/webpack.cjs",
"import": "./lib/webpack.mjs"
"import": "./lib/webpack.mjs",
"require": "./lib/webpack.cjs"
},
"./types": {
"types": "./types.d.ts"
"import": {
"types": "./lib/types.d.mts"
},
"require": {
"types": "./lib/types.d.cts"
}
},
"./messages": {
"types": "./messages.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/unplugin-vue-i18n/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"lib": ["esnext"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down
45 changes: 30 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27ec73f

Please sign in to comment.