@zthun/janitor-vite 21.1.3 → 21.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,10 @@ import { Plugin } from 'vite';
20
20
  * to a system by themselves. They are bundled with the overarching parent
21
21
  * application.
22
22
  *
23
+ * Note that if you combine this with something like node or nest, which
24
+ * expects a main.mts file as the entry point, that entry point goes away
25
+ * and the index.mts file will take over.
26
+ *
23
27
  * @returns
24
28
  * The list of plugins that turn any project into a library.
25
29
  */
package/dist/index.cjs CHANGED
@@ -134,6 +134,10 @@ function resolveCwd(current) {
134
134
  * to a system by themselves. They are bundled with the overarching parent
135
135
  * application.
136
136
  *
137
+ * Note that if you combine this with something like node or nest, which
138
+ * expects a main.mts file as the entry point, that entry point goes away
139
+ * and the index.mts file will take over.
140
+ *
137
141
  * @returns
138
142
  * The list of plugins that turn any project into a library.
139
143
  */ function extensionLibrary() {
@@ -148,6 +152,7 @@ function resolveCwd(current) {
148
152
  name: "janitor:extension-library",
149
153
  config: (current) => {
150
154
  const cwd = resolveCwd(current);
155
+ delete current?.build?.lib;
151
156
  return { build: {
152
157
  minify: false,
153
158
  sourcemap: true,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["extensionDevServer","options","port","host","name","config","server","allowedHosts","strictPort","builtinModules","modules","getAllNodeBuiltins","map","m","RegExp","readFileSync","getAllPackageDependencies","pkg","externals","Set","contents","toString","dependencies","devDependencies","optionalDependencies","peerDependencies","JSON","parse","push","add","bind","Object","keys","concat","map","dep","RegExp","forEach","Array","from","resolveCwd","current","root","process","cwd","resolve","getAllNodeBuiltins","getAllPackageDependencies","resolveCwd","extensionExternalize","options","name","config","current","cwd","fallback","packageJson","externalDeps","Set","forEach","p","add","depMatchers","Array","from","build","rolldownOptions","external","source","some","depMatcher","test","resolve","castArray","dts","resolveCwd","extensionExternalize","extensionLibrary","compilerOptions","paths","include","exclude","name","config","current","cwd","build","minify","sourcemap","lib","entry","index","formats","swc","project","vite","jsc","transform","react","runtime","name","config","oxc","resolve","tsconfigPaths","build","chunkSizeWarningLimit","minify","sourcemap","rolldownOptions","checks","pluginTimings","test","globals","testTimeout","maxConcurrency","resolve","extensionExternalize","resolveCwd","project","projectNode","packageJson","name","config","current","cwd","conditions","mainFields","build","lib","entry","main","formats","projectNode","projectCli","name","project","projectDom","name","config","test","environment","pool","environmentOptions","happyDOM","settings","handleDisabledFileLoadingAsSuccess","resolveCwd","project","projectMonorepo","name","config","current","cwd","test","projects","projectNode","projectNestJs","name","react","projectDom","projectReact","name","config","oxc"],"sources":["../src/extensions/extension-dev-server.mts","../src/helpful/get-all-node-builtins.mts","../src/helpful/get-all-package-dependencies.mts","../src/helpful/resolve-cwd.mts","../src/extensions/extension-externalize.mts","../src/extensions/extension-library.mts","../src/projects/project.mts","../src/projects/project-node.mts","../src/projects/project-cli.mts","../src/projects/project-dom.mts","../src/projects/project-monorepo.mts","../src/projects/project-nestjs.mts","../src/projects/project-react.mts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the dev server.\n *\n * The expectation for almost every repository in this instance\n * is that it is running the backend and frontend in a docker\n * compose environment, so it assumes it will be running in a docker\n * network. \n *\n * If this isn't true, then these options will be useful.\n */\nexport interface ExtensionDevServerOptions {\n /**\n * The port to run on. \n *\n * @default 5173\n */\n port?: number;\n\n /**\n * The binding host.\n *\n * @default \"0.0.0.0\"\n */\n host?: string;\n}\n\n/**\n * Adds a dev server to your vite build.\n *\n * This is usually paired with a dom based project and\n * is only used for debugging. AllowedHosts in this plugin\n * is set to true to allow for local manipulation of the\n * OS host file to simulate true domains.\n *\n * @returns\n * A list of plugins that add the dev server option.\n */\nexport function extensionDevServer(\n options: ExtensionDevServerOptions = {},\n): Plugin[] {\n const { port = 5173, host = \"0.0.0.0\" } = options;\n\n return [\n {\n name: \"janitor:extension-dev-server\",\n config: () => {\n return {\n server: {\n allowedHosts: true,\n strictPort: true,\n host,\n port,\n },\n };\n },\n },\n ];\n}\n","import { builtinModules as modules } from \"node:module\";\n\nexport function getAllNodeBuiltins(): RegExp[] {\n return modules.map((m) => new RegExp(`^(?:node:)?${m}$`));\n}\n","import { type PathLike, readFileSync } from \"node:fs\";\n\nexport function getAllPackageDependencies(pkg: PathLike): RegExp[] {\n try {\n const externals = new Set<RegExp>();\n\n const contents = readFileSync(pkg).toString();\n const {\n dependencies = [],\n devDependencies = [],\n optionalDependencies = [],\n peerDependencies = [],\n } = JSON.parse(contents) as Record<string, Record<string, string>>;\n\n const push = externals.add.bind(externals);\n\n Object.keys(dependencies)\n .concat(Object.keys(devDependencies))\n .concat(Object.keys(optionalDependencies))\n .concat(Object.keys(peerDependencies))\n .map((dep) => new RegExp(`^${dep}(?:/.+)?$`))\n .forEach(push);\n\n return Array.from(externals);\n } catch {\n return [];\n }\n}\n","import type { UserConfig } from \"vite\";\n\nexport function resolveCwd(current?: UserConfig): string {\n return current?.root || process.cwd();\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport { getAllNodeBuiltins } from \"../helpful/get-all-node-builtins.mjs\";\nimport { getAllPackageDependencies } from \"../helpful/get-all-package-dependencies.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\n\n/**\n * Options for externalizing dependencies.\n */\nexport interface ExternalizeOptions {\n /**\n * The path to the package json file that contains dependencies\n * to externalize or false to only externalize node builtins.\n *\n * If this is undefined, then the package.json in the current\n * working directory will be used.\n */\n packageJson?: PathLike | false;\n}\n\n/**\n * An externalize extension tells a project to not bundle the dependencies together. \n *\n * This is mostly used for libraries and if you use extensionLibrary(), or projectNode()\n * you do not need to include this extension as it will be included for you already.\n *\n * @param options -\n * Optional options for how to externalize dependency values.\n *\n * @returns\n * A list of plugins that will stop vite from bundling packages\n * from the node_modules directory and node builtins.\n */\nexport const extensionExternalize = (\n options: ExternalizeOptions = {},\n): Plugin[] => {\n return [\n {\n name: \"janitor:extension-externalize\",\n config: (current) => {\n const cwd = resolveCwd(current);\n const fallback = resolve(cwd, \"package.json\");\n const { packageJson = fallback } = options;\n const externalDeps = new Set<RegExp>(getAllNodeBuiltins());\n\n if (packageJson !== false) {\n getAllPackageDependencies(packageJson).forEach((p) =>\n externalDeps.add(p),\n );\n }\n\n const depMatchers = Array.from(externalDeps);\n\n return {\n build: {\n rolldownOptions: {\n external: (source) => {\n return depMatchers.some((depMatcher) =>\n depMatcher.test(source),\n );\n },\n },\n },\n } satisfies UserConfig;\n },\n },\n ];\n};\n","import { resolve } from \"node:path\";\n\nimport { castArray } from \"lodash-es\";\nimport dts from \"unplugin-dts/vite\";\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { extensionExternalize } from \"./extension-externalize.mjs\";\n\n/**\n * Turns any project into a shared library.\n *\n * A library does not actually run any code, it simply contains shared\n * code that makes up other projects.\n *\n * A library is expected to have an index.mts file under the src directory\n * that is a long list of exports that the library will provide to consumers.\n * Only one barrel export should be used for a library. It's better to have\n * multiple libraries than to complicate a library with subpaths in the\n * exports of package.json. This keeps the expectations that when you npm\n * library \"foo\", you can do import { something } from 'foo' and not need to\n * have the brain overload of hunting down available paths from within.\n *\n * When you classify something as a library, source maps are turned on,\n * and none of your code for it will be minified. This is to help with\n * debugging library code outside of the library development environment.\n * Module libraries in the janitor system are not expected to be deployed\n * to a system by themselves. They are bundled with the overarching parent\n * application.\n *\n * @returns\n * The list of plugins that turn any project into a library.\n */\nexport function extensionLibrary(): Plugin[] {\n return [\n ...extensionExternalize(),\n ...castArray(\n dts({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n // We only want to include output source files, not any config files outside\n // of our source code directory.\n include: [\"src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n // Make sure to exclude spec and test files as well, these don't need to\n // be included (and shouldn't be).\n exclude: [\"**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n }),\n ),\n {\n name: \"janitor:extension-library\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n build: {\n minify: false,\n sourcemap: true,\n lib: {\n entry: {\n index: resolve(cwd, \"./src/index.mts\"),\n },\n formats: [\"cjs\", \"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import swc from \"unplugin-swc\";\nimport type { Plugin } from \"vite\";\n\n/**\n * The base plugin for all project types.\n *\n * This will be included with every project. The default build engine for all projects\n * is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate\n * implementation of the latest ECMAScript features which gives us one unified build engine.\n *\n * A vite build should only include one project type and as many extensions as it wants.\n *\n * @returns\n * A list of plugins that all project types will provide.\n */\nexport function project(): Plugin[] {\n return [\n swc.vite({\n jsc: {\n transform: {\n react: {\n runtime: \"automatic\",\n },\n },\n },\n }),\n {\n name: \"janitor:project\",\n config: () => {\n return {\n oxc: false,\n resolve: {\n tsconfigPaths: true,\n },\n build: {\n chunkSizeWarningLimit: 8000,\n minify: true,\n sourcemap: false,\n rolldownOptions: {\n checks: {\n pluginTimings: false,\n },\n },\n },\n test: {\n globals: true,\n testTimeout: 20000,\n maxConcurrency: 10,\n },\n };\n },\n },\n ];\n}\n","import { resolve } from \"node:path\";\n\nimport type { Plugin } from \"vite\";\n\nimport { extensionExternalize } from \"../extensions/extension-externalize.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A plugin that marks a project as a node application.\n *\n * Node applications expect an entry point of main.mts under the\n * src directory.\n *\n * @returns\n * A list of plugins that turn a project into a node base cli\n * project.\n */\nexport function projectNode(): Plugin[] {\n return [\n ...project(),\n ...extensionExternalize({ packageJson: false }),\n {\n name: \"janitor:project-node\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n resolve: {\n conditions: [\"module\", \"node\", \"development|production\"],\n mainFields: [\"module\", \"jsnext:main\", \"jsnext\"],\n },\n build: {\n lib: {\n entry: {\n main: resolve(cwd, \"./src/main.mts\"),\n },\n formats: [\"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into a cli.\n */\nexport function projectCli(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-cli\",\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { project } from \"./project.mjs\";\n\n/**\n * A project for the DOM is a frontend application built with\n * basic web components, html, and css.\n *\n * Frontend projects with frameworks will automatically have this plugin.\n *\n * This will set the testing environment to happy-dom.\n *\n * @returns\n * A list of plugins that setup a vite build as a project for\n * a frontend.\n */\nexport function projectDom(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-dom\",\n config: () => {\n return {\n test: {\n environment: \"happy-dom\",\n pool: \"vmThreads\",\n environmentOptions: {\n happyDOM: {\n settings: {\n // This is to shut up happy-dom yelling about not being able\n // to download some injected css files.\n handleDisabledFileLoadingAsSuccess: true,\n },\n },\n },\n },\n };\n },\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A special project type for the root vite config or vitest config where\n * the repository is a monorepo of packages that use more than one config entry\n * for each package.\n *\n * This should only be set in a monorepo where the root just specifies which\n * packages the monorepo outputs. It sets up vitest to look for vite.config\n * files under each package.\n *\n * @returns\n * The list of plugins to use for the root monorepo.\n */\nexport function projectMonorepo(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-monorepo\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n test: {\n projects: [\n `${cwd}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`,\n ],\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into an app that\n * runs a NestJS backend.\n */\nexport function projectNestJs(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-nestjs\",\n },\n ];\n}\n","import react from \"@vitejs/plugin-react-swc\";\nimport type { Plugin } from \"vite\";\n\nimport { projectDom } from \"./project-dom.mjs\";\n\n/**\n * A project that builds out a react website.\n *\n * A react website is just a dom project that has the\n * react swc plugin enabled.\n *\n * This should normally be coupled with the server extension\n * for full debugging support.\n *\n * @returns\n * A list of plugins that builds a react website.\n */\nexport function projectReact(): Plugin[] {\n return [\n ...projectDom(),\n ...react(),\n {\n name: \"janitor:project-react\",\n config: () => {\n return {\n oxc: false,\n };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCA,SAAgBA,mBACdC,UAAqC,CAAC,GAAC;CAEvC,MAAM,EAAEC,OAAO,MAAMC,OAAO,cAAcF;CAE1C,OAAO,CACL;EACEG,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,QAAQ;IACNC,cAAc;IACdC,YAAY;IACZL;IACAD;GACF,EACF;EACF;CACF,CACD;AACH;;;ACzDA,SAAgBS,qBAAAA;CACd,OAAOD,YAAAA,eAAQE,KAAKC,MAAM,IAAIC,OAAO,cAAcD,EAAE,EAAE,CAAA;AACzD;;;ACFA,SAAgBG,0BAA0BC,KAAa;CACrD,IAAI;EACF,MAAMC,4BAAY,IAAIC,IAAAA;EAEtB,MAAMC,YAAAA,GAAWL,QAAAA,aAAAA,CAAaE,GAAAA,CAAAA,CAAKI,SAAQ;EAC3C,MAAM,EACJC,eAAe,CAAA,GACfC,kBAAkB,CAAA,GAClBC,uBAAuB,CAAA,GACvBC,mBAAmB,CAAA,MACjBC,KAAKC,MAAMP,QAAAA;EAEf,MAAMQ,OAAOV,UAAUW,IAA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;;;;;;GClCA,SAAgBE,aAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,sBACR,CACD;AACH;;;;;;;;;;;;;;GCCA,SAAgBE,aAAAA;CACd,OAAO,CACFD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,MAAM;IACJC,aAAa;IACbC,MAAM;IACNC,oBAAoB,EAClBC,UAAU,EACRC,UAAU,EAGRC,oCAAoC,KACtC,EACF,EACF;GACF,EACF;EACF;CACF,CACD;AACH;;;;;;;;;;;;;;GCvBA,SAAgBG,kBAAAA;CACd,OAAO,CACFD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,SAASC,YAAAA;GAGP,OAAO,EACLE,MAAM,EACJC,UAAU,CACR,GALMR,WAAWK,OAKdC,EAAI,qDACR,EACH,EACF;EACF;CACF,CACD;AACH;;;;;;;;;GC1BA,SAAgBI,gBAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,yBACR,CACD;AACH;;;;;;;;;;;;;;GCDA,SAAgBG,eAAAA;CACd,OAAO;EACFD,GAAAA,WAAAA;EACAD,IAAAA,GAAAA,yBAAAA,QAAAA,CAAAA;EACH;GACEG,MAAM;GACNC,cAAQ;IACN,OAAO,EACLC,KAAK,MACP;GACF;EACF;CACD;AACH"}
1
+ {"version":3,"file":"index.cjs","names":["extensionDevServer","options","port","host","name","config","server","allowedHosts","strictPort","builtinModules","modules","getAllNodeBuiltins","map","m","RegExp","readFileSync","getAllPackageDependencies","pkg","externals","Set","contents","toString","dependencies","devDependencies","optionalDependencies","peerDependencies","JSON","parse","push","add","bind","Object","keys","concat","map","dep","RegExp","forEach","Array","from","resolveCwd","current","root","process","cwd","resolve","getAllNodeBuiltins","getAllPackageDependencies","resolveCwd","extensionExternalize","options","name","config","current","cwd","fallback","packageJson","externalDeps","Set","forEach","p","add","depMatchers","Array","from","build","rolldownOptions","external","source","some","depMatcher","test","resolve","castArray","dts","resolveCwd","extensionExternalize","extensionLibrary","compilerOptions","paths","include","exclude","name","config","current","cwd","build","lib","minify","sourcemap","entry","index","formats","swc","project","vite","jsc","transform","react","runtime","name","config","oxc","resolve","tsconfigPaths","build","chunkSizeWarningLimit","minify","sourcemap","rolldownOptions","checks","pluginTimings","test","globals","testTimeout","maxConcurrency","resolve","extensionExternalize","resolveCwd","project","projectNode","packageJson","name","config","current","cwd","conditions","mainFields","build","lib","entry","main","formats","projectNode","projectCli","name","project","projectDom","name","config","test","environment","pool","environmentOptions","happyDOM","settings","handleDisabledFileLoadingAsSuccess","resolveCwd","project","projectMonorepo","name","config","current","cwd","test","projects","projectNode","projectNestJs","name","react","projectDom","projectReact","name","config","oxc"],"sources":["../src/extensions/extension-dev-server.mts","../src/helpful/get-all-node-builtins.mts","../src/helpful/get-all-package-dependencies.mts","../src/helpful/resolve-cwd.mts","../src/extensions/extension-externalize.mts","../src/extensions/extension-library.mts","../src/projects/project.mts","../src/projects/project-node.mts","../src/projects/project-cli.mts","../src/projects/project-dom.mts","../src/projects/project-monorepo.mts","../src/projects/project-nestjs.mts","../src/projects/project-react.mts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the dev server.\n *\n * The expectation for almost every repository in this instance\n * is that it is running the backend and frontend in a docker\n * compose environment, so it assumes it will be running in a docker\n * network. \n *\n * If this isn't true, then these options will be useful.\n */\nexport interface ExtensionDevServerOptions {\n /**\n * The port to run on. \n *\n * @default 5173\n */\n port?: number;\n\n /**\n * The binding host.\n *\n * @default \"0.0.0.0\"\n */\n host?: string;\n}\n\n/**\n * Adds a dev server to your vite build.\n *\n * This is usually paired with a dom based project and\n * is only used for debugging. AllowedHosts in this plugin\n * is set to true to allow for local manipulation of the\n * OS host file to simulate true domains.\n *\n * @returns\n * A list of plugins that add the dev server option.\n */\nexport function extensionDevServer(\n options: ExtensionDevServerOptions = {},\n): Plugin[] {\n const { port = 5173, host = \"0.0.0.0\" } = options;\n\n return [\n {\n name: \"janitor:extension-dev-server\",\n config: () => {\n return {\n server: {\n allowedHosts: true,\n strictPort: true,\n host,\n port,\n },\n };\n },\n },\n ];\n}\n","import { builtinModules as modules } from \"node:module\";\n\nexport function getAllNodeBuiltins(): RegExp[] {\n return modules.map((m) => new RegExp(`^(?:node:)?${m}$`));\n}\n","import { type PathLike, readFileSync } from \"node:fs\";\n\nexport function getAllPackageDependencies(pkg: PathLike): RegExp[] {\n try {\n const externals = new Set<RegExp>();\n\n const contents = readFileSync(pkg).toString();\n const {\n dependencies = [],\n devDependencies = [],\n optionalDependencies = [],\n peerDependencies = [],\n } = JSON.parse(contents) as Record<string, Record<string, string>>;\n\n const push = externals.add.bind(externals);\n\n Object.keys(dependencies)\n .concat(Object.keys(devDependencies))\n .concat(Object.keys(optionalDependencies))\n .concat(Object.keys(peerDependencies))\n .map((dep) => new RegExp(`^${dep}(?:/.+)?$`))\n .forEach(push);\n\n return Array.from(externals);\n } catch {\n return [];\n }\n}\n","import type { UserConfig } from \"vite\";\n\nexport function resolveCwd(current?: UserConfig): string {\n return current?.root || process.cwd();\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport { getAllNodeBuiltins } from \"../helpful/get-all-node-builtins.mjs\";\nimport { getAllPackageDependencies } from \"../helpful/get-all-package-dependencies.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\n\n/**\n * Options for externalizing dependencies.\n */\nexport interface ExternalizeOptions {\n /**\n * The path to the package json file that contains dependencies\n * to externalize or false to only externalize node builtins.\n *\n * If this is undefined, then the package.json in the current\n * working directory will be used.\n */\n packageJson?: PathLike | false;\n}\n\n/**\n * An externalize extension tells a project to not bundle the dependencies together. \n *\n * This is mostly used for libraries and if you use extensionLibrary(), or projectNode()\n * you do not need to include this extension as it will be included for you already.\n *\n * @param options -\n * Optional options for how to externalize dependency values.\n *\n * @returns\n * A list of plugins that will stop vite from bundling packages\n * from the node_modules directory and node builtins.\n */\nexport const extensionExternalize = (\n options: ExternalizeOptions = {},\n): Plugin[] => {\n return [\n {\n name: \"janitor:extension-externalize\",\n config: (current) => {\n const cwd = resolveCwd(current);\n const fallback = resolve(cwd, \"package.json\");\n const { packageJson = fallback } = options;\n const externalDeps = new Set<RegExp>(getAllNodeBuiltins());\n\n if (packageJson !== false) {\n getAllPackageDependencies(packageJson).forEach((p) =>\n externalDeps.add(p),\n );\n }\n\n const depMatchers = Array.from(externalDeps);\n\n return {\n build: {\n rolldownOptions: {\n external: (source) => {\n return depMatchers.some((depMatcher) =>\n depMatcher.test(source),\n );\n },\n },\n },\n } satisfies UserConfig;\n },\n },\n ];\n};\n","import { resolve } from \"node:path\";\n\nimport { castArray } from \"lodash-es\";\nimport dts from \"unplugin-dts/vite\";\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { extensionExternalize } from \"./extension-externalize.mjs\";\n\n/**\n * Turns any project into a shared library.\n *\n * A library does not actually run any code, it simply contains shared\n * code that makes up other projects.\n *\n * A library is expected to have an index.mts file under the src directory\n * that is a long list of exports that the library will provide to consumers.\n * Only one barrel export should be used for a library. It's better to have\n * multiple libraries than to complicate a library with subpaths in the\n * exports of package.json. This keeps the expectations that when you npm\n * library \"foo\", you can do import { something } from 'foo' and not need to\n * have the brain overload of hunting down available paths from within.\n *\n * When you classify something as a library, source maps are turned on,\n * and none of your code for it will be minified. This is to help with\n * debugging library code outside of the library development environment.\n * Module libraries in the janitor system are not expected to be deployed\n * to a system by themselves. They are bundled with the overarching parent\n * application.\n *\n * Note that if you combine this with something like node or nest, which\n * expects a main.mts file as the entry point, that entry point goes away\n * and the index.mts file will take over.\n *\n * @returns\n * The list of plugins that turn any project into a library.\n */\nexport function extensionLibrary(): Plugin[] {\n return [\n ...extensionExternalize(),\n ...castArray(\n dts({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n // We only want to include output source files, not any config files outside\n // of our source code directory.\n include: [\"src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n // Make sure to exclude spec and test files as well, these don't need to\n // be included (and shouldn't be).\n exclude: [\"**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n }),\n ),\n {\n name: \"janitor:extension-library\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n // The library extension fully controls the lib, so if we have additional\n // formats or entry points, those have to go away.\n delete current?.build?.lib;\n\n return {\n build: {\n minify: false,\n sourcemap: true,\n lib: {\n entry: {\n index: resolve(cwd, \"./src/index.mts\"),\n },\n formats: [\"cjs\", \"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import swc from \"unplugin-swc\";\nimport type { Plugin } from \"vite\";\n\n/**\n * The base plugin for all project types.\n *\n * This will be included with every project. The default build engine for all projects\n * is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate\n * implementation of the latest ECMAScript features which gives us one unified build engine.\n *\n * A vite build should only include one project type and as many extensions as it wants.\n *\n * @returns\n * A list of plugins that all project types will provide.\n */\nexport function project(): Plugin[] {\n return [\n swc.vite({\n jsc: {\n transform: {\n react: {\n runtime: \"automatic\",\n },\n },\n },\n }),\n {\n name: \"janitor:project\",\n config: () => {\n return {\n oxc: false,\n resolve: {\n tsconfigPaths: true,\n },\n build: {\n chunkSizeWarningLimit: 8000,\n minify: true,\n sourcemap: false,\n rolldownOptions: {\n checks: {\n pluginTimings: false,\n },\n },\n },\n test: {\n globals: true,\n testTimeout: 20000,\n maxConcurrency: 10,\n },\n };\n },\n },\n ];\n}\n","import { resolve } from \"node:path\";\n\nimport type { Plugin } from \"vite\";\n\nimport { extensionExternalize } from \"../extensions/extension-externalize.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A plugin that marks a project as a node application.\n *\n * Node applications expect an entry point of main.mts under the\n * src directory.\n *\n * @returns\n * A list of plugins that turn a project into a node base cli\n * project.\n */\nexport function projectNode(): Plugin[] {\n return [\n ...project(),\n ...extensionExternalize({ packageJson: false }),\n {\n name: \"janitor:project-node\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n resolve: {\n conditions: [\"module\", \"node\", \"development|production\"],\n mainFields: [\"module\", \"jsnext:main\", \"jsnext\"],\n },\n build: {\n lib: {\n entry: {\n main: resolve(cwd, \"./src/main.mts\"),\n },\n formats: [\"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into a cli.\n */\nexport function projectCli(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-cli\",\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { project } from \"./project.mjs\";\n\n/**\n * A project for the DOM is a frontend application built with\n * basic web components, html, and css.\n *\n * Frontend projects with frameworks will automatically have this plugin.\n *\n * This will set the testing environment to happy-dom.\n *\n * @returns\n * A list of plugins that setup a vite build as a project for\n * a frontend.\n */\nexport function projectDom(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-dom\",\n config: () => {\n return {\n test: {\n environment: \"happy-dom\",\n pool: \"vmThreads\",\n environmentOptions: {\n happyDOM: {\n settings: {\n // This is to shut up happy-dom yelling about not being able\n // to download some injected css files.\n handleDisabledFileLoadingAsSuccess: true,\n },\n },\n },\n },\n };\n },\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A special project type for the root vite config or vitest config where\n * the repository is a monorepo of packages that use more than one config entry\n * for each package.\n *\n * This should only be set in a monorepo where the root just specifies which\n * packages the monorepo outputs. It sets up vitest to look for vite.config\n * files under each package.\n *\n * @returns\n * The list of plugins to use for the root monorepo.\n */\nexport function projectMonorepo(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-monorepo\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n test: {\n projects: [\n `${cwd}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`,\n ],\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into an app that\n * runs a NestJS backend.\n */\nexport function projectNestJs(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-nestjs\",\n },\n ];\n}\n","import react from \"@vitejs/plugin-react-swc\";\nimport type { Plugin } from \"vite\";\n\nimport { projectDom } from \"./project-dom.mjs\";\n\n/**\n * A project that builds out a react website.\n *\n * A react website is just a dom project that has the\n * react swc plugin enabled.\n *\n * This should normally be coupled with the server extension\n * for full debugging support.\n *\n * @returns\n * A list of plugins that builds a react website.\n */\nexport function projectReact(): Plugin[] {\n return [\n ...projectDom(),\n ...react(),\n {\n name: \"janitor:project-react\",\n config: () => {\n return {\n oxc: false,\n };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCA,SAAgBA,mBACdC,UAAqC,CAAC,GAAC;CAEvC,MAAM,EAAEC,OAAO,MAAMC,OAAO,cAAcF;CAE1C,OAAO,CACL;EACEG,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,QAAQ;IACNC,cAAc;IACdC,YAAY;IACZL;IACAD;GACF,EACF;EACF;CACF,CACD;AACH;;;ACzDA,SAAgBS,qBAAAA;CACd,OAAOD,YAAAA,eAAQE,KAAKC,MAAM,IAAIC,OAAO,cAAcD,EAAE,EAAE,CAAA;AACzD;;;ACFA,SAAgBG,0BAA0BC,KAAa;CACrD,IAAI;EACF,MAAMC,4BAAY,IAAIC,IAAAA;EAEtB,MAAMC,YAAAA,GA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AAS;MACPU,YAAY;OAAC;OAAU;OAAQ;MAAyB;MACxDC,YAAY;OAAC;OAAU;OAAe;MAAS;KACjD;KACAC,OAAO,EACLC,KAAK;MACHC,OAAO,EACLC,OAAAA,GAAMf,UAAAA,QAAAA,CAAQS,KAAK,gBAAA,EACrB;MACAO,SAAS,CAAC,IAAK;KACjB,EACF;IACF;GACF;EACF;CACD;AACH;;;;;;;;GClCA,SAAgBE,aAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,sBACR,CACD;AACH;;;;;;;;;;;;;;GCCA,SAAgBE,aAAAA;CACd,OAAO,CACFD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,MAAM;IACJC,aAAa;IACbC,MAAM;IACNC,oBAAoB,EAClBC,UAAU,EACRC,UAAU,EAGRC,oCAAoC,KACtC,EACF,EACF;GACF,EACF;EACF;CACF,CACD;AACH;;;;;;;;;;;;;;GCvBA,SAAgBG,kBAAAA;CACd,OAAO,CACFD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,SAASC,YAAAA;GAGP,OAAO,EACLE,MAAM,EACJC,UAAU,CACR,GALMR,WAAWK,OAKdC,EAAI,qDACR,EACH,EACF;EACF;CACF,CACD;AACH;;;;;;;;;GC1BA,SAAgBI,gBAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,yBACR,CACD;AACH;;;;;;;;;;;;;;GCDA,SAAgBG,eAAAA;CACd,OAAO;EACFD,GAAAA,WAAAA;EACAD,IAAAA,GAAAA,yBAAAA,QAAAA,CAAAA;EACH;GACEG,MAAM;GACNC,cAAQ;IACN,OAAO,EACLC,KAAK,MACP;GACF;EACF;CACD;AACH"}
package/dist/index.js CHANGED
@@ -108,6 +108,10 @@ function resolveCwd(current) {
108
108
  * to a system by themselves. They are bundled with the overarching parent
109
109
  * application.
110
110
  *
111
+ * Note that if you combine this with something like node or nest, which
112
+ * expects a main.mts file as the entry point, that entry point goes away
113
+ * and the index.mts file will take over.
114
+ *
111
115
  * @returns
112
116
  * The list of plugins that turn any project into a library.
113
117
  */ function extensionLibrary() {
@@ -122,6 +126,7 @@ function resolveCwd(current) {
122
126
  name: "janitor:extension-library",
123
127
  config: (current) => {
124
128
  const cwd = resolveCwd(current);
129
+ delete current?.build?.lib;
125
130
  return { build: {
126
131
  minify: false,
127
132
  sourcemap: true,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["extensionDevServer","options","port","host","name","config","server","allowedHosts","strictPort","builtinModules","modules","getAllNodeBuiltins","map","m","RegExp","readFileSync","getAllPackageDependencies","pkg","externals","Set","contents","toString","dependencies","devDependencies","optionalDependencies","peerDependencies","JSON","parse","push","add","bind","Object","keys","concat","map","dep","RegExp","forEach","Array","from","resolveCwd","current","root","process","cwd","resolve","getAllNodeBuiltins","getAllPackageDependencies","resolveCwd","extensionExternalize","options","name","config","current","cwd","fallback","packageJson","externalDeps","Set","forEach","p","add","depMatchers","Array","from","build","rolldownOptions","external","source","some","depMatcher","test","resolve","castArray","dts","resolveCwd","extensionExternalize","extensionLibrary","compilerOptions","paths","include","exclude","name","config","current","cwd","build","minify","sourcemap","lib","entry","index","formats","swc","project","vite","jsc","transform","react","runtime","name","config","oxc","resolve","tsconfigPaths","build","chunkSizeWarningLimit","minify","sourcemap","rolldownOptions","checks","pluginTimings","test","globals","testTimeout","maxConcurrency","resolve","extensionExternalize","resolveCwd","project","projectNode","packageJson","name","config","current","cwd","conditions","mainFields","build","lib","entry","main","formats","projectNode","projectCli","name","project","projectDom","name","config","test","environment","pool","environmentOptions","happyDOM","settings","handleDisabledFileLoadingAsSuccess","resolveCwd","project","projectMonorepo","name","config","current","cwd","test","projects","projectNode","projectNestJs","name","react","projectDom","projectReact","name","config","oxc"],"sources":["../src/extensions/extension-dev-server.mts","../src/helpful/get-all-node-builtins.mts","../src/helpful/get-all-package-dependencies.mts","../src/helpful/resolve-cwd.mts","../src/extensions/extension-externalize.mts","../src/extensions/extension-library.mts","../src/projects/project.mts","../src/projects/project-node.mts","../src/projects/project-cli.mts","../src/projects/project-dom.mts","../src/projects/project-monorepo.mts","../src/projects/project-nestjs.mts","../src/projects/project-react.mts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the dev server.\n *\n * The expectation for almost every repository in this instance\n * is that it is running the backend and frontend in a docker\n * compose environment, so it assumes it will be running in a docker\n * network. \n *\n * If this isn't true, then these options will be useful.\n */\nexport interface ExtensionDevServerOptions {\n /**\n * The port to run on. \n *\n * @default 5173\n */\n port?: number;\n\n /**\n * The binding host.\n *\n * @default \"0.0.0.0\"\n */\n host?: string;\n}\n\n/**\n * Adds a dev server to your vite build.\n *\n * This is usually paired with a dom based project and\n * is only used for debugging. AllowedHosts in this plugin\n * is set to true to allow for local manipulation of the\n * OS host file to simulate true domains.\n *\n * @returns\n * A list of plugins that add the dev server option.\n */\nexport function extensionDevServer(\n options: ExtensionDevServerOptions = {},\n): Plugin[] {\n const { port = 5173, host = \"0.0.0.0\" } = options;\n\n return [\n {\n name: \"janitor:extension-dev-server\",\n config: () => {\n return {\n server: {\n allowedHosts: true,\n strictPort: true,\n host,\n port,\n },\n };\n },\n },\n ];\n}\n","import { builtinModules as modules } from \"node:module\";\n\nexport function getAllNodeBuiltins(): RegExp[] {\n return modules.map((m) => new RegExp(`^(?:node:)?${m}$`));\n}\n","import { type PathLike, readFileSync } from \"node:fs\";\n\nexport function getAllPackageDependencies(pkg: PathLike): RegExp[] {\n try {\n const externals = new Set<RegExp>();\n\n const contents = readFileSync(pkg).toString();\n const {\n dependencies = [],\n devDependencies = [],\n optionalDependencies = [],\n peerDependencies = [],\n } = JSON.parse(contents) as Record<string, Record<string, string>>;\n\n const push = externals.add.bind(externals);\n\n Object.keys(dependencies)\n .concat(Object.keys(devDependencies))\n .concat(Object.keys(optionalDependencies))\n .concat(Object.keys(peerDependencies))\n .map((dep) => new RegExp(`^${dep}(?:/.+)?$`))\n .forEach(push);\n\n return Array.from(externals);\n } catch {\n return [];\n }\n}\n","import type { UserConfig } from \"vite\";\n\nexport function resolveCwd(current?: UserConfig): string {\n return current?.root || process.cwd();\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport { getAllNodeBuiltins } from \"../helpful/get-all-node-builtins.mjs\";\nimport { getAllPackageDependencies } from \"../helpful/get-all-package-dependencies.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\n\n/**\n * Options for externalizing dependencies.\n */\nexport interface ExternalizeOptions {\n /**\n * The path to the package json file that contains dependencies\n * to externalize or false to only externalize node builtins.\n *\n * If this is undefined, then the package.json in the current\n * working directory will be used.\n */\n packageJson?: PathLike | false;\n}\n\n/**\n * An externalize extension tells a project to not bundle the dependencies together. \n *\n * This is mostly used for libraries and if you use extensionLibrary(), or projectNode()\n * you do not need to include this extension as it will be included for you already.\n *\n * @param options -\n * Optional options for how to externalize dependency values.\n *\n * @returns\n * A list of plugins that will stop vite from bundling packages\n * from the node_modules directory and node builtins.\n */\nexport const extensionExternalize = (\n options: ExternalizeOptions = {},\n): Plugin[] => {\n return [\n {\n name: \"janitor:extension-externalize\",\n config: (current) => {\n const cwd = resolveCwd(current);\n const fallback = resolve(cwd, \"package.json\");\n const { packageJson = fallback } = options;\n const externalDeps = new Set<RegExp>(getAllNodeBuiltins());\n\n if (packageJson !== false) {\n getAllPackageDependencies(packageJson).forEach((p) =>\n externalDeps.add(p),\n );\n }\n\n const depMatchers = Array.from(externalDeps);\n\n return {\n build: {\n rolldownOptions: {\n external: (source) => {\n return depMatchers.some((depMatcher) =>\n depMatcher.test(source),\n );\n },\n },\n },\n } satisfies UserConfig;\n },\n },\n ];\n};\n","import { resolve } from \"node:path\";\n\nimport { castArray } from \"lodash-es\";\nimport dts from \"unplugin-dts/vite\";\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { extensionExternalize } from \"./extension-externalize.mjs\";\n\n/**\n * Turns any project into a shared library.\n *\n * A library does not actually run any code, it simply contains shared\n * code that makes up other projects.\n *\n * A library is expected to have an index.mts file under the src directory\n * that is a long list of exports that the library will provide to consumers.\n * Only one barrel export should be used for a library. It's better to have\n * multiple libraries than to complicate a library with subpaths in the\n * exports of package.json. This keeps the expectations that when you npm\n * library \"foo\", you can do import { something } from 'foo' and not need to\n * have the brain overload of hunting down available paths from within.\n *\n * When you classify something as a library, source maps are turned on,\n * and none of your code for it will be minified. This is to help with\n * debugging library code outside of the library development environment.\n * Module libraries in the janitor system are not expected to be deployed\n * to a system by themselves. They are bundled with the overarching parent\n * application.\n *\n * @returns\n * The list of plugins that turn any project into a library.\n */\nexport function extensionLibrary(): Plugin[] {\n return [\n ...extensionExternalize(),\n ...castArray(\n dts({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n // We only want to include output source files, not any config files outside\n // of our source code directory.\n include: [\"src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n // Make sure to exclude spec and test files as well, these don't need to\n // be included (and shouldn't be).\n exclude: [\"**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n }),\n ),\n {\n name: \"janitor:extension-library\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n build: {\n minify: false,\n sourcemap: true,\n lib: {\n entry: {\n index: resolve(cwd, \"./src/index.mts\"),\n },\n formats: [\"cjs\", \"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import swc from \"unplugin-swc\";\nimport type { Plugin } from \"vite\";\n\n/**\n * The base plugin for all project types.\n *\n * This will be included with every project. The default build engine for all projects\n * is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate\n * implementation of the latest ECMAScript features which gives us one unified build engine.\n *\n * A vite build should only include one project type and as many extensions as it wants.\n *\n * @returns\n * A list of plugins that all project types will provide.\n */\nexport function project(): Plugin[] {\n return [\n swc.vite({\n jsc: {\n transform: {\n react: {\n runtime: \"automatic\",\n },\n },\n },\n }),\n {\n name: \"janitor:project\",\n config: () => {\n return {\n oxc: false,\n resolve: {\n tsconfigPaths: true,\n },\n build: {\n chunkSizeWarningLimit: 8000,\n minify: true,\n sourcemap: false,\n rolldownOptions: {\n checks: {\n pluginTimings: false,\n },\n },\n },\n test: {\n globals: true,\n testTimeout: 20000,\n maxConcurrency: 10,\n },\n };\n },\n },\n ];\n}\n","import { resolve } from \"node:path\";\n\nimport type { Plugin } from \"vite\";\n\nimport { extensionExternalize } from \"../extensions/extension-externalize.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A plugin that marks a project as a node application.\n *\n * Node applications expect an entry point of main.mts under the\n * src directory.\n *\n * @returns\n * A list of plugins that turn a project into a node base cli\n * project.\n */\nexport function projectNode(): Plugin[] {\n return [\n ...project(),\n ...extensionExternalize({ packageJson: false }),\n {\n name: \"janitor:project-node\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n resolve: {\n conditions: [\"module\", \"node\", \"development|production\"],\n mainFields: [\"module\", \"jsnext:main\", \"jsnext\"],\n },\n build: {\n lib: {\n entry: {\n main: resolve(cwd, \"./src/main.mts\"),\n },\n formats: [\"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into a cli.\n */\nexport function projectCli(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-cli\",\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { project } from \"./project.mjs\";\n\n/**\n * A project for the DOM is a frontend application built with\n * basic web components, html, and css.\n *\n * Frontend projects with frameworks will automatically have this plugin.\n *\n * This will set the testing environment to happy-dom.\n *\n * @returns\n * A list of plugins that setup a vite build as a project for\n * a frontend.\n */\nexport function projectDom(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-dom\",\n config: () => {\n return {\n test: {\n environment: \"happy-dom\",\n pool: \"vmThreads\",\n environmentOptions: {\n happyDOM: {\n settings: {\n // This is to shut up happy-dom yelling about not being able\n // to download some injected css files.\n handleDisabledFileLoadingAsSuccess: true,\n },\n },\n },\n },\n };\n },\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A special project type for the root vite config or vitest config where\n * the repository is a monorepo of packages that use more than one config entry\n * for each package.\n *\n * This should only be set in a monorepo where the root just specifies which\n * packages the monorepo outputs. It sets up vitest to look for vite.config\n * files under each package.\n *\n * @returns\n * The list of plugins to use for the root monorepo.\n */\nexport function projectMonorepo(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-monorepo\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n test: {\n projects: [\n `${cwd}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`,\n ],\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into an app that\n * runs a NestJS backend.\n */\nexport function projectNestJs(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-nestjs\",\n },\n ];\n}\n","import react from \"@vitejs/plugin-react-swc\";\nimport type { Plugin } from \"vite\";\n\nimport { projectDom } from \"./project-dom.mjs\";\n\n/**\n * A project that builds out a react website.\n *\n * A react website is just a dom project that has the\n * react swc plugin enabled.\n *\n * This should normally be coupled with the server extension\n * for full debugging support.\n *\n * @returns\n * A list of plugins that builds a react website.\n */\nexport function projectReact(): Plugin[] {\n return [\n ...projectDom(),\n ...react(),\n {\n name: \"janitor:project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;;;;;;;;GCDA,SAAgBG,eAAAA;CACd,OAAO;EACFD,GAAAA,WAAAA;EACAD,GAAAA,MAAAA;EACH;GACEG,MAAM;GACNC,cAAQ;IACN,OAAO,EACLC,KAAK,MACP;GACF;EACF;CACD;AACH"}
1
+ {"version":3,"file":"index.js","names":["extensionDevServer","options","port","host","name","config","server","allowedHosts","strictPort","builtinModules","modules","getAllNodeBuiltins","map","m","RegExp","readFileSync","getAllPackageDependencies","pkg","externals","Set","contents","toString","dependencies","devDependencies","optionalDependencies","peerDependencies","JSON","parse","push","add","bind","Object","keys","concat","map","dep","RegExp","forEach","Array","from","resolveCwd","current","root","process","cwd","resolve","getAllNodeBuiltins","getAllPackageDependencies","resolveCwd","extensionExternalize","options","name","config","current","cwd","fallback","packageJson","externalDeps","Set","forEach","p","add","depMatchers","Array","from","build","rolldownOptions","external","source","some","depMatcher","test","resolve","castArray","dts","resolveCwd","extensionExternalize","extensionLibrary","compilerOptions","paths","include","exclude","name","config","current","cwd","build","lib","minify","sourcemap","entry","index","formats","swc","project","vite","jsc","transform","react","runtime","name","config","oxc","resolve","tsconfigPaths","build","chunkSizeWarningLimit","minify","sourcemap","rolldownOptions","checks","pluginTimings","test","globals","testTimeout","maxConcurrency","resolve","extensionExternalize","resolveCwd","project","projectNode","packageJson","name","config","current","cwd","conditions","mainFields","build","lib","entry","main","formats","projectNode","projectCli","name","project","projectDom","name","config","test","environment","pool","environmentOptions","happyDOM","settings","handleDisabledFileLoadingAsSuccess","resolveCwd","project","projectMonorepo","name","config","current","cwd","test","projects","projectNode","projectNestJs","name","react","projectDom","projectReact","name","config","oxc"],"sources":["../src/extensions/extension-dev-server.mts","../src/helpful/get-all-node-builtins.mts","../src/helpful/get-all-package-dependencies.mts","../src/helpful/resolve-cwd.mts","../src/extensions/extension-externalize.mts","../src/extensions/extension-library.mts","../src/projects/project.mts","../src/projects/project-node.mts","../src/projects/project-cli.mts","../src/projects/project-dom.mts","../src/projects/project-monorepo.mts","../src/projects/project-nestjs.mts","../src/projects/project-react.mts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the dev server.\n *\n * The expectation for almost every repository in this instance\n * is that it is running the backend and frontend in a docker\n * compose environment, so it assumes it will be running in a docker\n * network. \n *\n * If this isn't true, then these options will be useful.\n */\nexport interface ExtensionDevServerOptions {\n /**\n * The port to run on. \n *\n * @default 5173\n */\n port?: number;\n\n /**\n * The binding host.\n *\n * @default \"0.0.0.0\"\n */\n host?: string;\n}\n\n/**\n * Adds a dev server to your vite build.\n *\n * This is usually paired with a dom based project and\n * is only used for debugging. AllowedHosts in this plugin\n * is set to true to allow for local manipulation of the\n * OS host file to simulate true domains.\n *\n * @returns\n * A list of plugins that add the dev server option.\n */\nexport function extensionDevServer(\n options: ExtensionDevServerOptions = {},\n): Plugin[] {\n const { port = 5173, host = \"0.0.0.0\" } = options;\n\n return [\n {\n name: \"janitor:extension-dev-server\",\n config: () => {\n return {\n server: {\n allowedHosts: true,\n strictPort: true,\n host,\n port,\n },\n };\n },\n },\n ];\n}\n","import { builtinModules as modules } from \"node:module\";\n\nexport function getAllNodeBuiltins(): RegExp[] {\n return modules.map((m) => new RegExp(`^(?:node:)?${m}$`));\n}\n","import { type PathLike, readFileSync } from \"node:fs\";\n\nexport function getAllPackageDependencies(pkg: PathLike): RegExp[] {\n try {\n const externals = new Set<RegExp>();\n\n const contents = readFileSync(pkg).toString();\n const {\n dependencies = [],\n devDependencies = [],\n optionalDependencies = [],\n peerDependencies = [],\n } = JSON.parse(contents) as Record<string, Record<string, string>>;\n\n const push = externals.add.bind(externals);\n\n Object.keys(dependencies)\n .concat(Object.keys(devDependencies))\n .concat(Object.keys(optionalDependencies))\n .concat(Object.keys(peerDependencies))\n .map((dep) => new RegExp(`^${dep}(?:/.+)?$`))\n .forEach(push);\n\n return Array.from(externals);\n } catch {\n return [];\n }\n}\n","import type { UserConfig } from \"vite\";\n\nexport function resolveCwd(current?: UserConfig): string {\n return current?.root || process.cwd();\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport { getAllNodeBuiltins } from \"../helpful/get-all-node-builtins.mjs\";\nimport { getAllPackageDependencies } from \"../helpful/get-all-package-dependencies.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\n\n/**\n * Options for externalizing dependencies.\n */\nexport interface ExternalizeOptions {\n /**\n * The path to the package json file that contains dependencies\n * to externalize or false to only externalize node builtins.\n *\n * If this is undefined, then the package.json in the current\n * working directory will be used.\n */\n packageJson?: PathLike | false;\n}\n\n/**\n * An externalize extension tells a project to not bundle the dependencies together. \n *\n * This is mostly used for libraries and if you use extensionLibrary(), or projectNode()\n * you do not need to include this extension as it will be included for you already.\n *\n * @param options -\n * Optional options for how to externalize dependency values.\n *\n * @returns\n * A list of plugins that will stop vite from bundling packages\n * from the node_modules directory and node builtins.\n */\nexport const extensionExternalize = (\n options: ExternalizeOptions = {},\n): Plugin[] => {\n return [\n {\n name: \"janitor:extension-externalize\",\n config: (current) => {\n const cwd = resolveCwd(current);\n const fallback = resolve(cwd, \"package.json\");\n const { packageJson = fallback } = options;\n const externalDeps = new Set<RegExp>(getAllNodeBuiltins());\n\n if (packageJson !== false) {\n getAllPackageDependencies(packageJson).forEach((p) =>\n externalDeps.add(p),\n );\n }\n\n const depMatchers = Array.from(externalDeps);\n\n return {\n build: {\n rolldownOptions: {\n external: (source) => {\n return depMatchers.some((depMatcher) =>\n depMatcher.test(source),\n );\n },\n },\n },\n } satisfies UserConfig;\n },\n },\n ];\n};\n","import { resolve } from \"node:path\";\n\nimport { castArray } from \"lodash-es\";\nimport dts from \"unplugin-dts/vite\";\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { extensionExternalize } from \"./extension-externalize.mjs\";\n\n/**\n * Turns any project into a shared library.\n *\n * A library does not actually run any code, it simply contains shared\n * code that makes up other projects.\n *\n * A library is expected to have an index.mts file under the src directory\n * that is a long list of exports that the library will provide to consumers.\n * Only one barrel export should be used for a library. It's better to have\n * multiple libraries than to complicate a library with subpaths in the\n * exports of package.json. This keeps the expectations that when you npm\n * library \"foo\", you can do import { something } from 'foo' and not need to\n * have the brain overload of hunting down available paths from within.\n *\n * When you classify something as a library, source maps are turned on,\n * and none of your code for it will be minified. This is to help with\n * debugging library code outside of the library development environment.\n * Module libraries in the janitor system are not expected to be deployed\n * to a system by themselves. They are bundled with the overarching parent\n * application.\n *\n * Note that if you combine this with something like node or nest, which\n * expects a main.mts file as the entry point, that entry point goes away\n * and the index.mts file will take over.\n *\n * @returns\n * The list of plugins that turn any project into a library.\n */\nexport function extensionLibrary(): Plugin[] {\n return [\n ...extensionExternalize(),\n ...castArray(\n dts({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n // We only want to include output source files, not any config files outside\n // of our source code directory.\n include: [\"src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n // Make sure to exclude spec and test files as well, these don't need to\n // be included (and shouldn't be).\n exclude: [\"**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n }),\n ),\n {\n name: \"janitor:extension-library\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n // The library extension fully controls the lib, so if we have additional\n // formats or entry points, those have to go away.\n delete current?.build?.lib;\n\n return {\n build: {\n minify: false,\n sourcemap: true,\n lib: {\n entry: {\n index: resolve(cwd, \"./src/index.mts\"),\n },\n formats: [\"cjs\", \"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import swc from \"unplugin-swc\";\nimport type { Plugin } from \"vite\";\n\n/**\n * The base plugin for all project types.\n *\n * This will be included with every project. The default build engine for all projects\n * is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate\n * implementation of the latest ECMAScript features which gives us one unified build engine.\n *\n * A vite build should only include one project type and as many extensions as it wants.\n *\n * @returns\n * A list of plugins that all project types will provide.\n */\nexport function project(): Plugin[] {\n return [\n swc.vite({\n jsc: {\n transform: {\n react: {\n runtime: \"automatic\",\n },\n },\n },\n }),\n {\n name: \"janitor:project\",\n config: () => {\n return {\n oxc: false,\n resolve: {\n tsconfigPaths: true,\n },\n build: {\n chunkSizeWarningLimit: 8000,\n minify: true,\n sourcemap: false,\n rolldownOptions: {\n checks: {\n pluginTimings: false,\n },\n },\n },\n test: {\n globals: true,\n testTimeout: 20000,\n maxConcurrency: 10,\n },\n };\n },\n },\n ];\n}\n","import { resolve } from \"node:path\";\n\nimport type { Plugin } from \"vite\";\n\nimport { extensionExternalize } from \"../extensions/extension-externalize.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A plugin that marks a project as a node application.\n *\n * Node applications expect an entry point of main.mts under the\n * src directory.\n *\n * @returns\n * A list of plugins that turn a project into a node base cli\n * project.\n */\nexport function projectNode(): Plugin[] {\n return [\n ...project(),\n ...extensionExternalize({ packageJson: false }),\n {\n name: \"janitor:project-node\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n resolve: {\n conditions: [\"module\", \"node\", \"development|production\"],\n mainFields: [\"module\", \"jsnext:main\", \"jsnext\"],\n },\n build: {\n lib: {\n entry: {\n main: resolve(cwd, \"./src/main.mts\"),\n },\n formats: [\"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into a cli.\n */\nexport function projectCli(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-cli\",\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { project } from \"./project.mjs\";\n\n/**\n * A project for the DOM is a frontend application built with\n * basic web components, html, and css.\n *\n * Frontend projects with frameworks will automatically have this plugin.\n *\n * This will set the testing environment to happy-dom.\n *\n * @returns\n * A list of plugins that setup a vite build as a project for\n * a frontend.\n */\nexport function projectDom(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-dom\",\n config: () => {\n return {\n test: {\n environment: \"happy-dom\",\n pool: \"vmThreads\",\n environmentOptions: {\n happyDOM: {\n settings: {\n // This is to shut up happy-dom yelling about not being able\n // to download some injected css files.\n handleDisabledFileLoadingAsSuccess: true,\n },\n },\n },\n },\n };\n },\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A special project type for the root vite config or vitest config where\n * the repository is a monorepo of packages that use more than one config entry\n * for each package.\n *\n * This should only be set in a monorepo where the root just specifies which\n * packages the monorepo outputs. It sets up vitest to look for vite.config\n * files under each package.\n *\n * @returns\n * The list of plugins to use for the root monorepo.\n */\nexport function projectMonorepo(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-monorepo\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n test: {\n projects: [\n `${cwd}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`,\n ],\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into an app that\n * runs a NestJS backend.\n */\nexport function projectNestJs(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-nestjs\",\n },\n ];\n}\n","import react from \"@vitejs/plugin-react-swc\";\nimport type { Plugin } from \"vite\";\n\nimport { projectDom } from \"./project-dom.mjs\";\n\n/**\n * A project that builds out a react website.\n *\n * A react website is just a dom project that has the\n * react swc plugin enabled.\n *\n * This should normally be coupled with the server extension\n * for full debugging support.\n *\n * @returns\n * A list of plugins that builds a react website.\n */\nexport function projectReact(): Plugin[] {\n return [\n ...projectDom(),\n ...react(),\n {\n name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AA,GACH,EACEE,MAAM,yBACR,CACD;AACH;;;;;;;;;;;;;;GCDA,SAAgBG,eAAAA;CACd,OAAO;EACFD,GAAAA,WAAAA;EACAD,GAAAA,MAAAA;EACH;GACEG,MAAM;GACNC,cAAQ;IACN,OAAO,EACLC,KAAK,MACP;GACF;EACF;CACD;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/janitor-vite",
3
- "version": "21.1.3",
3
+ "version": "21.1.4",
4
4
  "description": "A shared set of plugins for vite that use conventions over configuration",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.mts",
@@ -53,5 +53,5 @@
53
53
  "access": "public"
54
54
  },
55
55
  "author": "Anthony Bonta",
56
- "gitHead": "515d79ef605f4f4f0374d94e0b74c04f71f2b72d"
56
+ "gitHead": "d9c17bc69d35d823f79b8c2c471b30f6f02480f7"
57
57
  }