diff --git a/package.json b/package.json index 4efae11..9cca41b 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "description": "code-style for naverpay", "scripts": { "prepare": "husky install", + "build": "turbo build", "lint": "eslint", "lint:fix": "pnpm run lint --fix", "prettier": "prettier --check '**/*.{json,yaml,md,ts,tsx,js,jsx}'", diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index 56029a5..1db7c1f 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -1,10 +1,8 @@ -import fs from 'node:fs' - import node from './configs/node.js' import front from './configs/front.js' import typescript from './configs/typescript.js' -const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')) +import pkg from './package.json' export default { meta: { diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index f3ec1cf..c31855d 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -3,12 +3,22 @@ "version": "1.0.7", "description": "eslint config for naverpay", "type": "module", - "main": "./index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.mjs", "exports": { - "import": "./index.js", - "default": "./index.js" + ".": { + "import": "./dist/esm/index.mjs", + "require": "./dist/cjs/index.js", + "default": "./dist/cjs/index.js" + } }, + "files": [ + "dist" + ], "scripts": { + "clean": "rm -rf dist", + "prebuild": "pnpm run clean", + "build": "rollup -c", "test": "vitest run", "test:watch": "vitest watch", "version": "pnpm version", @@ -51,6 +61,9 @@ ], "license": "MIT", "devDependencies": { + "@rollup/plugin-json": "^6.1.0", + "builtin-modules": "^4.0.0", + "rollup": "^4.27.4", "vitest": "^2.1.5" } } diff --git a/packages/eslint-config/rollup.config.js b/packages/eslint-config/rollup.config.js new file mode 100644 index 0000000..f80b95b --- /dev/null +++ b/packages/eslint-config/rollup.config.js @@ -0,0 +1,32 @@ +import path from 'path' +import fs from 'fs' +import builtins from 'builtin-modules' +import json from '@rollup/plugin-json' + +/** + * @type {import('rollup').RollupOptions} + */ +export default ['esm', 'cjs'].map((module) => { + const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')) + + return { + input: 'index.js', + output: { + format: module, + dir: 'dist/' + module, + ...(module === 'esm' + ? { + entryFileNames: `[name]${path.extname('./dist/' + module + '/index.mjs')}`, + preserveModulesRoot: path.dirname('index.js'), + preserveModules: true, + interop: 'esModule', + } + : { + exports: 'auto', + interop: 'auto', + }), + }, + external: [...Object.keys(pkg?.dependencies || []), ...Object.keys(pkg?.peerDependencies || []), ...builtins], + plugins: [json()], + } +}) diff --git a/packages/eslint-plugin/lib/index.js b/packages/eslint-plugin/lib/index.js index f1187ba..33a3beb 100644 --- a/packages/eslint-plugin/lib/index.js +++ b/packages/eslint-plugin/lib/index.js @@ -1,12 +1,10 @@ -import fs from 'node:fs' - import memoReactComponents from './rules/memo-react-components.js' import optimizeSvgComponents from './rules/optimize-svg-components.js' import preventDefaultImport from './rules/prevent-default-import.js' import sortExports from './rules/sort-exports.js' import svgUniqueId from './rules/svg-unique-id.js' -const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')) +import pkg from '../package.json' const plugin = { meta: { diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 5fa39d4..5fd18ad 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -3,8 +3,22 @@ "version": "1.2.1", "description": "eslint plugin for naverpay", "type": "module", - "main": "./lib/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.mjs", + "exports": { + ".": { + "import": "./dist/esm/index.mjs", + "require": "./dist/cjs/index.js", + "default": "./dist/cjs/index.js" + } + }, + "files": [ + "dist" + ], "scripts": { + "clean": "rm -rf dist", + "prebuild": "pnpm run clean", + "build": "rollup -c", "test": "vitest run", "test:watch": "vitest watch", "version": "pnpm version", @@ -12,7 +26,10 @@ }, "devDependencies": { "@babel/eslint-parser": "^7.25.9", + "@rollup/plugin-json": "^6.1.0", "@typescript-eslint/parser": "^8.15.0", + "builtin-modules": "^4.0.0", + "rollup": "^4.27.4", "vitest": "^2.1.5" }, "peerDependencies": { diff --git a/packages/eslint-plugin/rollup.config.js b/packages/eslint-plugin/rollup.config.js new file mode 100644 index 0000000..f930cf9 --- /dev/null +++ b/packages/eslint-plugin/rollup.config.js @@ -0,0 +1,32 @@ +import path from 'path' +import fs from 'fs' +import builtins from 'builtin-modules' +import json from '@rollup/plugin-json' + +/** + * @type {import('rollup').RollupOptions} + */ +export default ['esm', 'cjs'].map((module) => { + const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')) + + return { + input: 'lib/index.js', + output: { + format: module, + dir: 'dist/' + module, + ...(module === 'esm' + ? { + entryFileNames: `[name]${path.extname('./dist/' + module + '/index.mjs')}`, + preserveModulesRoot: path.dirname('lib/index.js'), + preserveModules: true, + interop: 'esModule', + } + : { + exports: 'auto', + interop: 'auto', + }), + }, + external: [...Object.keys(pkg?.dependencies || []), ...Object.keys(pkg?.peerDependencies || []), ...builtins], + plugins: [json()], + } +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1ef0680..d9b21ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -113,6 +113,15 @@ importers: specifier: ^15.12.0 version: 15.12.0 devDependencies: + '@rollup/plugin-json': + specifier: ^6.1.0 + version: 6.1.0(rollup@4.27.4) + builtin-modules: + specifier: ^4.0.0 + version: 4.0.0 + rollup: + specifier: ^4.27.4 + version: 4.27.4 vitest: specifier: ^2.1.5 version: 2.1.5(terser@5.36.0) @@ -135,9 +144,18 @@ importers: '@babel/eslint-parser': specifier: ^7.25.9 version: 7.25.9(@babel/core@7.24.3)(eslint@9.15.0) + '@rollup/plugin-json': + specifier: ^6.1.0 + version: 6.1.0(rollup@4.27.4) '@typescript-eslint/parser': specifier: ^8.15.0 version: 8.15.0(eslint@9.15.0)(typescript@5.3.3) + builtin-modules: + specifier: ^4.0.0 + version: 4.0.0 + rollup: + specifier: ^4.27.4 + version: 4.27.4 vitest: specifier: ^2.1.5 version: 2.1.5(terser@5.36.0) @@ -875,6 +893,24 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@rollup/plugin-json@6.1.0': + resolution: {integrity: sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + + '@rollup/pluginutils@5.1.3': + resolution: {integrity: sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/rollup-android-arm-eabi@4.27.4': resolution: {integrity: sha512-2Y3JT6f5MrQkICUyRVCw4oa0sutfAsgaSsb0Lmmy1Wi2y7X5vT9Euqw4gOsCyy0YfKURBg35nhUKZS4mDcfULw==} cpu: [arm] @@ -1370,6 +1406,10 @@ packages: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} engines: {node: '>=6'} + builtin-modules@4.0.0: + resolution: {integrity: sha512-p1n8zyCkt1BVrKNFymOHjcDSAl7oq/gUvfgULv2EblgpPVQlQr9yHnWjg9IJ2MhfwPqiYqMMrr01OY7yQoK2yA==} + engines: {node: '>=18.20'} + cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -1939,6 +1979,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} @@ -3033,6 +3076,10 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} + pidtree@0.6.0: resolution: {integrity: sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==} engines: {node: '>=0.10'} @@ -4761,6 +4808,20 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@rollup/plugin-json@6.1.0(rollup@4.27.4)': + dependencies: + '@rollup/pluginutils': 5.1.3(rollup@4.27.4) + optionalDependencies: + rollup: 4.27.4 + + '@rollup/pluginutils@5.1.3(rollup@4.27.4)': + dependencies: + '@types/estree': 1.0.6 + estree-walker: 2.0.2 + picomatch: 4.0.2 + optionalDependencies: + rollup: 4.27.4 + '@rollup/rollup-android-arm-eabi@4.27.4': optional: true @@ -5299,6 +5360,8 @@ snapshots: builtin-modules@3.3.0: {} + builtin-modules@4.0.0: {} + cac@6.7.14: {} call-bind@1.0.7: @@ -5992,6 +6055,8 @@ snapshots: estraverse@5.3.0: {} + estree-walker@2.0.2: {} + estree-walker@3.0.3: dependencies: '@types/estree': 1.0.6 @@ -7259,6 +7324,8 @@ snapshots: picomatch@2.3.1: {} + picomatch@4.0.2: {} + pidtree@0.6.0: {} pify@4.0.1: {} @@ -7966,7 +8033,7 @@ snapshots: dependencies: browserslist: 4.23.0 escalade: 3.1.2 - picocolors: 1.0.0 + picocolors: 1.1.1 uri-js@4.4.1: dependencies: diff --git a/turbo.json b/turbo.json index fd60c62..20db253 100644 --- a/turbo.json +++ b/turbo.json @@ -2,6 +2,7 @@ "$schema": "https://turborepo.org/schema.json", "pipeline": { "test": {"cache": false}, - "test:watch": {"cache": false} + "test:watch": {"cache": false}, + "build": {"cache": false, "dependsOn": ["^build"]} } }