Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: move packages to ESM first #418

Merged
merged 1 commit into from
Nov 16, 2024
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
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 => {
Copy link
Member Author

@userquin userquin Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about removing the extra required .default when requiring vite or webpack plugin (I don't use default export anymore to avoid this, you can remove the hack, run pnpm build && pnpm pack from the package and upload the generated tgz to https://arethetypeswrong.github.io/ or just check https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseExportDefault.md):

const webpack = require('@intlify/unplugin-vue-i18n/webpack').default

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.