diff --git a/.cspell.json b/.cspell.json deleted file mode 100644 index fda995f4..00000000 --- a/.cspell.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "0.2", - "language": "en", - "words": [], - "ignorePaths": [ - "node_modules/**", - "tests/**/__snapshots__/**", - "coverage/**", - "esm/**", - "lib/**", - "umd/**", - "*.tsbuildinfo", - "tests/page/input.txt", - "cc-test-reporter", - "package.json", - "package-lock.json" - ] -} diff --git a/.gitignore b/.gitignore index 9387c5d3..a556cbb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -lib -esm -umd +/out *.tsbuildinfo ### https://raw.github.com/github/gitignore/4a8e0a151becd5ccbb83e4aca6e6c195f3d506fd/Global/macOS.gitignore @@ -11,7 +9,8 @@ umd .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* diff --git a/biome.json b/biome.json index b6fc070f..c2eccbbf 100644 --- a/biome.json +++ b/biome.json @@ -2,7 +2,7 @@ "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", "organizeImports": { "enabled": true }, "files": { - "ignore": ["./lib", "./esm", "./umd", "./coverage"] + "ignore": ["./out", "./coverage"] }, "linter": { "enabled": true diff --git a/package.json b/package.json index 66d2248f..20481116 100644 --- a/package.json +++ b/package.json @@ -3,29 +3,28 @@ "version": "9.0.0", "type": "module", "description": "parse Scrapbox notation to JavaScript Object", - "files": ["lib", "esm", "umd"], - "main": "./lib/index.js", - "module": "./esm/index.js", - "types": "./lib/index.d.ts", - "unpkg": "./umd/scrapbox-parser.umd.cjs", + "files": ["out"], + "main": "./out/index.cjs", + "module": "./out/index.mjs", + "types": "./out/types/index.d.ts", + "unpkg": "./out/scrapbox-parser.umd.js", "exports": { - "import": "./esm/index.js", - "require": "./lib/index.js", - "node": "./esm/index.js", - "default": "./lib/index.js" + "import": "./out/index.mjs", + "require": "./out/index.cjs", + "node": "./out/index.mjs", + "default": "./out/index.cjs" }, "scripts": { + "prebuild": "node -e 'fs.rmSync(`out`, {recursive:true, force:true})'", "build": "run-p build:*", - "build:cjs": "tsc -p ./tsconfig.cjs.json", - "build:esm": "tsc -p ./tsconfig.esm.json", - "build:umd": "vite build", - "prepare": "run-s clean build", - "clean": "node -e '[`lib`, `esm`, `umd`, `.cjs.tsbuildinfo`, `.esm.tsbuildinfo`].forEach(path => { fs.rmSync(path, {recursive:true, force:true}) })'", + "build:types": "tsc -p ./tsconfig.json", + "build:vite": "vite build", + "prepare": "npm run build", "test": "vitest run --coverage", "test:update": "vitest run --updateSnapshot --no-cache", "lint": "run-p lint:*", "lint:biome": "biome check .", - "lint:tsc": "tsc -p ./tsconfig.eslint.json", + "lint:tsc": "tsc -p ./tsconfig.lint.json", "format": "biome check --write ." }, "repository": { diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json deleted file mode 100644 index dea287ec..00000000 --- a/tsconfig.cjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "commonjs", - "rootDir": "./src", - "outDir": "./lib", - "tsBuildInfoFile": "./.cjs.tsbuildinfo" - } -} diff --git a/tsconfig.esm.json b/tsconfig.esm.json deleted file mode 100644 index 3948e474..00000000 --- a/tsconfig.esm.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "es2015", - "rootDir": "./src", - "outDir": "./esm", - "tsBuildInfoFile": "./.esm.tsbuildinfo" - } -} diff --git a/tsconfig.json b/tsconfig.json index c78683dc..91bb8e93 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,8 @@ /* Visit https://aka.ms/tsconfig to read more about this file */ /* Projects */ - "incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */, - "composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */, + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ @@ -25,9 +25,9 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs" /* Specify what module code is generated. */, + "module": "Preserve" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, + "moduleResolution": "Bundler" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ @@ -35,7 +35,7 @@ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ @@ -51,7 +51,7 @@ /* Emit */ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, "declarationMap": true /* Create sourcemaps for d.ts files. */, - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + "emitDeclarationOnly": true /* Only output d.ts files and not JavaScript files. */, // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ @@ -69,11 +69,11 @@ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + "declarationDir": "./out" /* Specify the output directory for generated declaration files. */, /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + "verbatimModuleSyntax": true /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */, // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, diff --git a/tsconfig.eslint.json b/tsconfig.lint.json similarity index 100% rename from tsconfig.eslint.json rename to tsconfig.lint.json diff --git a/vite.config.ts b/vite.config.ts index c5b2a576..d5f57ced 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,22 +1,30 @@ /// import { resolve } from "node:path"; -import { defineConfig } from "vite"; +import { defineConfig, type LibraryFormats } from "vite"; + +const formats = ["es", "cjs", "umd"] satisfies LibraryFormats[]; export default defineConfig({ - build: { - emptyOutDir: false, - outDir: "umd", - lib: { - formats: ["umd"], - entry: resolve(__dirname, "src/index.ts"), - name: "ScrapboxParser", - fileName: "scrapbox-parser", - }, - }, - test: { - include: ["**/tests/**/*.test.ts"], - coverage: { - include: ["src/**/*.ts"], - }, - }, + build: { + emptyOutDir: false, + outDir: "out", + lib: { + formats, + entry: resolve(__dirname, "src/index.ts"), + fileName: (format) => + (( + { + cjs: "index.cjs", + es: "index.mjs", + umd: "scrapbox-parser.umd.js", + } satisfies Record<(typeof formats)[number], string> + )[format]), + }, + }, + test: { + include: ["**/tests/**/*.test.ts"], + coverage: { + include: ["src/**/*.ts"], + }, + }, });