diff --git a/README.md b/README.md index 26b35a658..14894d7ad 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,12 @@ scaleway-lib is a set of NPM packages used at Scaleway. ![npm bundle size](https://img.shields.io/bundlephobia/min/@scaleway/outdated-browser) ![npm](https://img.shields.io/npm/v/@scaleway/outdated-browser) +- [`@scaleway/validate-icu-locales`](./packages/validate-icu-locales/README.md): A small cli to check ICU locales error + + ![npm](https://img.shields.io/npm/dm/@scaleway/validate-icu-locales) + ![npm bundle size](https://img.shields.io/bundlephobia/min/@scaleway/validate-icu-locales) + ![npm](https://img.shields.io/npm/v/@scaleway/validate-icu-locales) + ## Development ### Locally diff --git a/package.json b/package.json index c1e76dde6..8624e31ec 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "packages/*" ], "type": "module", + "packageManager": "pnpm@7.14.0", "devDependencies": { "@babel/core": "7.19.6", "@babel/eslint-parser": "7.19.1", @@ -42,6 +43,7 @@ "read-pkg": "7.1.0", "rollup": "3.2.3", "rollup-plugin-dts": "5.0.0", + "rollup-plugin-preserve-shebangs": "^0.2.0", "rollup-plugin-visualizer": "5.8.3", "tsd-lite": "0.6.0", "typescript": "4.8.4", @@ -117,6 +119,5 @@ } ] ] - }, - "packageManager": "pnpm@7.14.0" + } } diff --git a/packages/validate-icu-locales/.eslintrc.cjs b/packages/validate-icu-locales/.eslintrc.cjs new file mode 100644 index 000000000..a2dbbe3d7 --- /dev/null +++ b/packages/validate-icu-locales/.eslintrc.cjs @@ -0,0 +1,10 @@ +const { join } = require('path') + +module.exports = { + rules: { + 'import/no-extraneous-dependencies': [ + 'error', + { packageDir: [__dirname, join(__dirname, '../../')] }, + ], + }, +} diff --git a/packages/validate-icu-locales/README.md b/packages/validate-icu-locales/README.md new file mode 100644 index 000000000..90bc5bc30 --- /dev/null +++ b/packages/validate-icu-locales/README.md @@ -0,0 +1,49 @@ +# `@scaleway/validate-icu-locales` + +## A tiny cli to handle ICU errors on locales files. +## Install + +Requirements +- Node should be installed + +```bash +$ pnpm add -D @scaleway/validate-icu-locales +``` +## Usage + +We can parse JSON, TS and JS if theses files use default export. + + +``` +validate-icu "../**/en.json" +``` + +If there is an error on a local, the CLI will throw an Error and print all errors. + + +## Error +``` +export default from: ../src/__tests__/locales/en-1.js is not an object +{ + errors: [ + { + message: 'EXPECT_ARGUMENT_CLOSING_BRACE', + value: '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + key: 'units.minutes.label', + filePath: '../../packages/validate-icu-locales/src/__tests__/locales/en.js' + }, + { + message: 'EXPECT_ARGUMENT_CLOSING_BRACE', + value: '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + key: 'units.minutes.label', + filePath: '../../packages/validate-icu-locales/src/__tests__/locales/en.json' + }, + { + message: 'EXPECT_ARGUMENT_CLOSING_BRACE', + value: '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + key: 'units.minutes.label', + filePath: '../../packages/validate-icu-locales/src/__tests__/locales/en.ts' + } + ] +} +``` \ No newline at end of file diff --git a/packages/validate-icu-locales/package.json b/packages/validate-icu-locales/package.json new file mode 100644 index 000000000..1a283f455 --- /dev/null +++ b/packages/validate-icu-locales/package.json @@ -0,0 +1,28 @@ +{ + "name": "@scaleway/validate-icu-locales", + "version": "1.0.0", + "description": "A small cli to handle icu errors on locales files", + "keywords": [ + "icu", + "i18n", + "cli" + ], + "type": "module", + "bin": { + "validate-icu": "dist/index.js" + }, + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/scaleway/scaleway-lib", + "directory": "packages/validate-icu-locales" + }, + "license": "MIT", + "dependencies": { + "@formatjs/icu-messageformat-parser": "^2.1.10", + "globby": "^13.1.2", + "module-from-string": "^3.3.0" + } +} diff --git a/packages/validate-icu-locales/src/__tests__/locales/en-1.js b/packages/validate-icu-locales/src/__tests__/locales/en-1.js new file mode 100644 index 000000000..8de515d93 --- /dev/null +++ b/packages/validate-icu-locales/src/__tests__/locales/en-1.js @@ -0,0 +1,9 @@ +export const locales = { + // error on this one missing bracket + + 'units.minutes.label': + '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + 'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}', + 'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}', + 'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}', +} diff --git a/packages/validate-icu-locales/src/__tests__/locales/en-no-default.ts b/packages/validate-icu-locales/src/__tests__/locales/en-no-default.ts new file mode 100644 index 000000000..e2c06bb72 --- /dev/null +++ b/packages/validate-icu-locales/src/__tests__/locales/en-no-default.ts @@ -0,0 +1,9 @@ +export const toto = { + // error on this one missing bracket + + 'units.minutes.label': + '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + 'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}', + 'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}', + 'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}', +} as const diff --git a/packages/validate-icu-locales/src/__tests__/locales/en-ts.ts b/packages/validate-icu-locales/src/__tests__/locales/en-ts.ts new file mode 100644 index 000000000..80f0cc89d --- /dev/null +++ b/packages/validate-icu-locales/src/__tests__/locales/en-ts.ts @@ -0,0 +1,9 @@ +export default { + // error on this one missing bracket + + 'units.minutes.label': + '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + 'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}', + 'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}', + 'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}', +} as const diff --git a/packages/validate-icu-locales/src/__tests__/locales/en.js b/packages/validate-icu-locales/src/__tests__/locales/en.js new file mode 100644 index 000000000..a08f33e18 --- /dev/null +++ b/packages/validate-icu-locales/src/__tests__/locales/en.js @@ -0,0 +1,9 @@ +export default { + // error on this one missing bracket + + 'units.minutes.label': + '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + 'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}', + 'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}', + 'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}', +} diff --git a/packages/validate-icu-locales/src/__tests__/locales/en.json b/packages/validate-icu-locales/src/__tests__/locales/en.json new file mode 100644 index 000000000..f80650343 --- /dev/null +++ b/packages/validate-icu-locales/src/__tests__/locales/en.json @@ -0,0 +1,6 @@ +{ + "units.minutes.label": "{count, plural, =0 {Minute} =1 {Minute} other {Minutes", + "units.hours.label": "{count, plural, =0 {Hour} =1 {Hour} other {Hours}}", + "units.days.label": "{count, plural, =0 {Day} =1 {Day} other {Days}}", + "units.months.label": "{count, plural, =0 {Month} =1 {Month} other {Months}}" +} diff --git a/packages/validate-icu-locales/src/__tests__/locales/en.ts b/packages/validate-icu-locales/src/__tests__/locales/en.ts new file mode 100644 index 000000000..80f0cc89d --- /dev/null +++ b/packages/validate-icu-locales/src/__tests__/locales/en.ts @@ -0,0 +1,9 @@ +export default { + // error on this one missing bracket + + 'units.minutes.label': + '{count, plural, =0 {Minute} =1 {Minute} other {Minutes', + 'units.hours.label': '{count, plural, =0 {Hour} =1 {Hour} other {Hours}}', + 'units.days.label': '{count, plural, =0 {Day} =1 {Day} other {Days}}', + 'units.months.label': '{count, plural, =0 {Month} =1 {Month} other {Months}}', +} as const diff --git a/packages/validate-icu-locales/src/index.ts b/packages/validate-icu-locales/src/index.ts new file mode 100644 index 000000000..6d6df1f24 --- /dev/null +++ b/packages/validate-icu-locales/src/index.ts @@ -0,0 +1,122 @@ +#!/usr/bin/env node + +import { parse } from '@formatjs/icu-messageformat-parser' +import { ParserError } from '@formatjs/icu-messageformat-parser/error' +import { readFile } from 'fs/promises' +import { globby } from 'globby' +import { importFromString } from 'module-from-string' + +const args = process.argv.slice(2) +const pattern = args[0] +const { error, table } = console + +type Locales = Record +type ErrorICU = { + message: ParserError['message'] + value: string + key: string + filePath: string +} + +type ErrorsICU = (ErrorICU | undefined)[] + +const isObject = (obj: unknown): obj is Record => + obj === Object(obj) + +const findICUErrors = ( + locales: { [key: string]: string }, + filePath: string, +): ErrorsICU => { + const keys = Object.keys(locales) + + const errors = keys + .map(key => { + const value = locales[key] + + try { + parse(value) + + return undefined + } catch (err) { + const { message } = err as ParserError + + return { + message, + value, + key, + filePath, + } + } + }) + .filter(Boolean) + + return errors +} + +const readFiles = async (files: string[]): Promise => { + const errors = [] + + for await (const file of files) { + const extension = file.split('.').pop() + + if (extension === 'json') { + try { + const data = await readFile(file) + const jsonFile = data.toString() + + const locales = JSON.parse(jsonFile) as Locales + + const ICUErrors = findICUErrors(locales, file) + errors.push(...ICUErrors) + } catch (err) { + error({ file, err }) + } + } + + if (extension === 'ts' || extension === 'js') { + try { + const data = await readFile(file) + const javascriptFile = data.toString() + + const mod: unknown = await importFromString(javascriptFile, { + transformOptions: { loader: 'ts' }, + }) + + if (isObject(mod)) { + if ('default' in mod) { + const { default: locales } = mod as { default: Locales } + + const ICUErrors = findICUErrors(locales, file) + errors.push(...ICUErrors) + } else { + error('export default from: ', file, ' is not an object') + } + } else { + error(file, ' is not an object') + } + } catch (err) { + error({ err, file }) + } + } + } + + return errors +} + +const files = await globby(pattern) + +if (files.length === 0) { + error('There is no files matching this pattern', pattern) + process.exit(1) +} + +table(files) + +const errors = await readFiles(files) + +if (errors.length > 0) { + error({ + errors, + }) + process.exit(1) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3df9d3cc3..9f4460eed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,6 +40,7 @@ importers: read-pkg: 7.1.0 rollup: 3.2.3 rollup-plugin-dts: 5.0.0 + rollup-plugin-preserve-shebangs: ^0.2.0 rollup-plugin-visualizer: 5.8.3 tsd-lite: 0.6.0 typescript: 4.8.4 @@ -81,6 +82,7 @@ importers: read-pkg: 7.1.0 rollup: 3.2.3 rollup-plugin-dts: 5.0.0_655ssj4e7sdqlljrreeiqtltve + rollup-plugin-preserve-shebangs: 0.2.0_rollup@3.2.3 rollup-plugin-visualizer: 5.8.3_rollup@3.2.3 tsd-lite: 0.6.0_@tsd+typescript@4.8.4 typescript: 4.8.4 @@ -203,6 +205,16 @@ importers: dependencies: '@segment/analytics-next': 1.45.0 + packages/validate-icu-locales: + specifiers: + '@formatjs/icu-messageformat-parser': ^2.1.10 + globby: ^13.1.2 + module-from-string: ^3.3.0 + dependencies: + '@formatjs/icu-messageformat-parser': 2.1.10 + globby: 13.1.2 + module-from-string: 3.3.0 + packages: /@adobe/css-tools/4.0.1: @@ -1795,6 +1807,24 @@ packages: resolution: {integrity: sha512-AHPmaAx+RYfZz0eYu6Gviiagpmiyw98ySSlQvCUhVGDRtDFe4DBS0x1bSjdF3gqUDYOczB+yYvBTtEylYSdRhg==} dev: false + /@esbuild/android-arm/0.15.12: + resolution: {integrity: sha512-IC7TqIqiyE0MmvAhWkl/8AEzpOtbhRNDo7aph47We1NbE5w2bt/Q+giAhe0YYeVpYnIhGMcuZY92qDK6dQauvA==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-loong64/0.15.12: + resolution: {integrity: sha512-tZEowDjvU7O7I04GYvWQOS4yyP9E/7YlsB0jjw1Ycukgr2ycEzKyIk5tms5WnLBymaewc6VmRKnn5IJWgK4eFw==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@eslint/eslintrc/1.3.3: resolution: {integrity: sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -6043,6 +6073,216 @@ packages: is-symbol: 1.0.4 dev: false + /esbuild-android-64/0.15.12: + resolution: {integrity: sha512-MJKXwvPY9g0rGps0+U65HlTsM1wUs9lbjt5CU19RESqycGFDRijMDQsh68MtbzkqWSRdEtiKS1mtPzKneaAI0Q==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /esbuild-android-arm64/0.15.12: + resolution: {integrity: sha512-Hc9SEcZbIMhhLcvhr1DH+lrrec9SFTiRzfJ7EGSBZiiw994gfkVV6vG0sLWqQQ6DD7V4+OggB+Hn0IRUdDUqvA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /esbuild-darwin-64/0.15.12: + resolution: {integrity: sha512-qkmqrTVYPFiePt5qFjP8w/S+GIUMbt6k8qmiPraECUWfPptaPJUGkCKrWEfYFRWB7bY23FV95rhvPyh/KARP8Q==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /esbuild-darwin-arm64/0.15.12: + resolution: {integrity: sha512-z4zPX02tQ41kcXMyN3c/GfZpIjKoI/BzHrdKUwhC/Ki5BAhWv59A9M8H+iqaRbwpzYrYidTybBwiZAIWCLJAkw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /esbuild-freebsd-64/0.15.12: + resolution: {integrity: sha512-XFL7gKMCKXLDiAiBjhLG0XECliXaRLTZh6hsyzqUqPUf/PY4C6EJDTKIeqqPKXaVJ8+fzNek88285krSz1QECw==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /esbuild-freebsd-arm64/0.15.12: + resolution: {integrity: sha512-jwEIu5UCUk6TjiG1X+KQnCGISI+ILnXzIzt9yDVrhjug2fkYzlLbl0K43q96Q3KB66v6N1UFF0r5Ks4Xo7i72g==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-32/0.15.12: + resolution: {integrity: sha512-uSQuSEyF1kVzGzuIr4XM+v7TPKxHjBnLcwv2yPyCz8riV8VUCnO/C4BF3w5dHiVpCd5Z1cebBtZJNlC4anWpwA==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-64/0.15.12: + resolution: {integrity: sha512-QcgCKb7zfJxqT9o5z9ZUeGH1k8N6iX1Y7VNsEi5F9+HzN1OIx7ESxtQXDN9jbeUSPiRH1n9cw6gFT3H4qbdvcA==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-arm/0.15.12: + resolution: {integrity: sha512-Wf7T0aNylGcLu7hBnzMvsTfEXdEdJY/hY3u36Vla21aY66xR0MS5I1Hw8nVquXjTN0A6fk/vnr32tkC/C2lb0A==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-arm64/0.15.12: + resolution: {integrity: sha512-HtNq5xm8fUpZKwWKS2/YGwSfTF+339L4aIA8yphNKYJckd5hVdhfdl6GM2P3HwLSCORS++++7++//ApEwXEuAQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-mips64le/0.15.12: + resolution: {integrity: sha512-Qol3+AvivngUZkTVFgLpb0H6DT+N5/zM3V1YgTkryPYFeUvuT5JFNDR3ZiS6LxhyF8EE+fiNtzwlPqMDqVcc6A==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-ppc64le/0.15.12: + resolution: {integrity: sha512-4D8qUCo+CFKaR0cGXtGyVsOI7w7k93Qxb3KFXWr75An0DHamYzq8lt7TNZKoOq/Gh8c40/aKaxvcZnTgQ0TJNg==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-riscv64/0.15.12: + resolution: {integrity: sha512-G9w6NcuuCI6TUUxe6ka0enjZHDnSVK8bO+1qDhMOCtl7Tr78CcZilJj8SGLN00zO5iIlwNRZKHjdMpfFgNn1VA==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-linux-s390x/0.15.12: + resolution: {integrity: sha512-Lt6BDnuXbXeqSlVuuUM5z18GkJAZf3ERskGZbAWjrQoi9xbEIsj/hEzVnSAFLtkfLuy2DE4RwTcX02tZFunXww==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /esbuild-netbsd-64/0.15.12: + resolution: {integrity: sha512-jlUxCiHO1dsqoURZDQts+HK100o0hXfi4t54MNRMCAqKGAV33JCVvMplLAa2FwviSojT/5ZG5HUfG3gstwAG8w==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: false + optional: true + + /esbuild-openbsd-64/0.15.12: + resolution: {integrity: sha512-1o1uAfRTMIWNOmpf8v7iudND0L6zRBYSH45sofCZywrcf7NcZA+c7aFsS1YryU+yN7aRppTqdUK1PgbZVaB1Dw==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: false + optional: true + + /esbuild-sunos-64/0.15.12: + resolution: {integrity: sha512-nkl251DpoWoBO9Eq9aFdoIt2yYmp4I3kvQjba3jFKlMXuqQ9A4q+JaqdkCouG3DHgAGnzshzaGu6xofGcXyPXg==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: false + optional: true + + /esbuild-windows-32/0.15.12: + resolution: {integrity: sha512-WlGeBZHgPC00O08luIp5B2SP4cNCp/PcS+3Pcg31kdcJPopHxLkdCXtadLU9J82LCfw4TVls21A6lilQ9mzHrw==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /esbuild-windows-64/0.15.12: + resolution: {integrity: sha512-VActO3WnWZSN//xjSfbiGOSyC+wkZtI8I4KlgrTo5oHJM6z3MZZBCuFaZHd8hzf/W9KPhF0lY8OqlmWC9HO5AA==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /esbuild-windows-arm64/0.15.12: + resolution: {integrity: sha512-Of3MIacva1OK/m4zCNIvBfz8VVROBmQT+gRX6pFTLPngFYcj6TFH/12VveAqq1k9VB2l28EoVMNMUCcmsfwyuA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /esbuild/0.15.12: + resolution: {integrity: sha512-PcT+/wyDqJQsRVhaE9uX/Oq4XLrFh0ce/bs2TJh4CSaw9xuvI+xFrH2nAYOADbhQjUgAhNWC5LKoUsakm4dxng==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/android-arm': 0.15.12 + '@esbuild/linux-loong64': 0.15.12 + esbuild-android-64: 0.15.12 + esbuild-android-arm64: 0.15.12 + esbuild-darwin-64: 0.15.12 + esbuild-darwin-arm64: 0.15.12 + esbuild-freebsd-64: 0.15.12 + esbuild-freebsd-arm64: 0.15.12 + esbuild-linux-32: 0.15.12 + esbuild-linux-64: 0.15.12 + esbuild-linux-arm: 0.15.12 + esbuild-linux-arm64: 0.15.12 + esbuild-linux-mips64le: 0.15.12 + esbuild-linux-ppc64le: 0.15.12 + esbuild-linux-riscv64: 0.15.12 + esbuild-linux-s390x: 0.15.12 + esbuild-netbsd-64: 0.15.12 + esbuild-openbsd-64: 0.15.12 + esbuild-sunos-64: 0.15.12 + esbuild-windows-32: 0.15.12 + esbuild-windows-64: 0.15.12 + esbuild-windows-arm64: 0.15.12 + dev: false + /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -6835,6 +7075,17 @@ packages: merge2: 1.4.1 slash: 3.0.0 + /globby/13.1.2: + resolution: {integrity: sha512-LKSDZXToac40u8Q1PQtZihbNdTYSNMuWe+K5l+oa6KgDzSvVrHXlJy40hUP522RjAIoNLJYBJi7ow+rbFpIhHQ==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + dir-glob: 3.0.1 + fast-glob: 3.2.12 + ignore: 5.2.0 + merge2: 1.4.1 + slash: 4.0.0 + dev: false + /graceful-fs/4.2.10: resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} dev: true @@ -8299,6 +8550,12 @@ packages: resolution: {integrity: sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==} hasBin: true + /magic-string/0.25.9: + resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==} + dependencies: + sourcemap-codec: 1.4.8 + dev: true + /magic-string/0.26.7: resolution: {integrity: sha512-hX9XH3ziStPoPhJxLq1syWuZMxbDvGNbVchfrdCtanC7D13888bMFow61x8axrx+GfHLtVeAx2kxL7tTGRl+Ow==} engines: {node: '>=12'} @@ -8544,6 +8801,14 @@ packages: engines: {node: '>=0.10.0'} dev: true + /module-from-string/3.3.0: + resolution: {integrity: sha512-VsjwtQtXZloDF7ZpBXON53U4Zz02K1/njJmfZcK+QDlYKgdL0ETq8/FeuU0G9EHxdG5XiTaITcGaldDAqJpGXA==} + engines: {node: '>=12.20.0'} + dependencies: + esbuild: 0.15.12 + nanoid: 3.3.4 + dev: false + /ms/2.0.0: resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} dev: false @@ -8569,6 +8834,12 @@ packages: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} dev: true + /nanoid/3.3.4: + resolution: {integrity: sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + dev: false + /natural-compare/1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -9707,6 +9978,15 @@ packages: '@babel/code-frame': 7.18.6 dev: true + /rollup-plugin-preserve-shebangs/0.2.0_rollup@3.2.3: + resolution: {integrity: sha512-OEyTIfZwUJ7yUAVAbegac/bNvp1WJzgZcQNCFprWX42wwwOqlJwrev9lUmzZdYVgCWct+03xUPvZg4RfgkM9oQ==} + peerDependencies: + rollup: '*' + dependencies: + magic-string: 0.25.9 + rollup: 3.2.3 + dev: true + /rollup-plugin-visualizer/5.8.3_rollup@3.2.3: resolution: {integrity: sha512-QGJk4Bqe4AOat5AjipOh8esZH1nck5X2KFpf4VytUdSUuuuSwvIQZjMGgjcxe/zXexltqaXp5Vx1V3LmnQH15Q==} engines: {node: '>=14'} @@ -9852,6 +10132,11 @@ packages: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} + /slash/4.0.0: + resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} + engines: {node: '>=12'} + dev: false + /slice-ansi/3.0.0: resolution: {integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==} engines: {node: '>=8'} diff --git a/rollup.config.mjs b/rollup.config.mjs index eed591703..484c3ad2b 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -3,6 +3,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve' import builtins from 'builtin-modules' import { readPackage } from 'read-pkg' import dts from 'rollup-plugin-dts' +import { preserveShebangs } from 'rollup-plugin-preserve-shebangs' import { visualizer } from 'rollup-plugin-visualizer' const PROFILE = !!process.env.PROFILE @@ -38,9 +39,7 @@ const getConfig = (pkg, isBrowser = false) => { comments: false, exclude: 'node_modules/**', extensions: ['.js', '.jsx', '.ts', '.tsx', '.es', '.mjs'], - plugins: [ - '@babel/plugin-transform-runtime', - ], + plugins: ['@babel/plugin-transform-runtime'], presets: [ ['@babel/env', { modules: false, targets }], '@babel/preset-typescript', @@ -54,9 +53,10 @@ const getConfig = (pkg, isBrowser = false) => { }), nodeResolve({ browser: isBrowser, - extensions: [ '.mjs', '.js', '.json', '.ts', '.tsx' ], + extensions: ['.mjs', '.js', '.json', '.ts', '.tsx'], preferBuiltins: true, }), + preserveShebangs(), PROFILE && visualizer({ brotliSize: true,