@sdeverywhere/plugin-vite 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Climate Interactive / New Venture Fund
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @sdeverywhere/plugin-vite
2
+
3
+ This package provides a plugin that uses Vite and a given Vite configuration file
4
+ to bundle an application or library as part of the SDEverywhere builder process
5
+ (i.e., `sde bundle` or `sde dev`).
6
+
7
+ ## Documentation
8
+
9
+ TODO
10
+
11
+ ## License
12
+
13
+ SDEverywhere is distributed under the MIT license. See `LICENSE` for more details.
package/dist/index.cjs ADDED
@@ -0,0 +1,85 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/index.ts
34
+ var src_exports = {};
35
+ __export(src_exports, {
36
+ vitePlugin: () => vitePlugin
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+
40
+ // src/plugin.ts
41
+ var import_vite = require("vite");
42
+ function vitePlugin(options) {
43
+ return new VitePlugin(options);
44
+ }
45
+ var VitePlugin = class {
46
+ constructor(options) {
47
+ this.options = options;
48
+ }
49
+ async postGenerate(context) {
50
+ return this.buildIfNeeded(context, "post-generate");
51
+ }
52
+ async postBuild(context) {
53
+ return this.buildIfNeeded(context, "post-build");
54
+ }
55
+ async buildIfNeeded(context, caller) {
56
+ var _a, _b;
57
+ const applyDev = ((_a = this.options.apply) == null ? void 0 : _a.development) || "post-build";
58
+ const applyProd = ((_b = this.options.apply) == null ? void 0 : _b.production) || "post-build";
59
+ const shouldBuild = context.config.mode === "development" && applyDev === caller || context.config.mode === "production" && applyProd === caller;
60
+ if (shouldBuild) {
61
+ context.log("info", `Building ${this.options.name}`);
62
+ await (0, import_vite.build)(this.options.config);
63
+ }
64
+ return true;
65
+ }
66
+ async watch() {
67
+ var _a, _b;
68
+ if (((_a = this.options.apply) == null ? void 0 : _a.development) === "serve") {
69
+ const server = await (0, import_vite.createServer)(this.options.config);
70
+ await server.listen();
71
+ } else if (((_b = this.options.apply) == null ? void 0 : _b.development) === "watch") {
72
+ const config = __spreadValues({
73
+ build: {
74
+ watch: {}
75
+ }
76
+ }, this.options.config);
77
+ await (0, import_vite.build)(config);
78
+ }
79
+ }
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ vitePlugin
84
+ });
85
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/plugin.ts"],"sourcesContent":["// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nexport type { VitePluginOptions } from './options'\nexport { vitePlugin } from './plugin'\n","// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nimport type { InlineConfig, ViteDevServer } from 'vite'\nimport { build, createServer } from 'vite'\n\nimport type { BuildContext, Plugin } from '@sdeverywhere/build'\n\nimport type { VitePluginOptions } from './options'\n\nexport function vitePlugin(options: VitePluginOptions): Plugin {\n return new VitePlugin(options)\n}\n\nclass VitePlugin implements Plugin {\n constructor(private readonly options: VitePluginOptions) {}\n\n async postGenerate(context: BuildContext): Promise<boolean> {\n // Only build if the plugin is configured to run for 'post-generate'\n return this.buildIfNeeded(context, 'post-generate')\n }\n\n async postBuild(context: BuildContext): Promise<boolean> {\n // Only build if the plugin is configured to run for 'post-build'\n return this.buildIfNeeded(context, 'post-build')\n }\n\n private async buildIfNeeded(context: BuildContext, caller: 'post-generate' | 'post-build'): Promise<boolean> {\n // The apply values default to 'post-build' when left undefined\n const applyDev = this.options.apply?.development || 'post-build'\n const applyProd = this.options.apply?.production || 'post-build'\n\n // Run \"vite build\" only if configured for this mode\n const shouldBuild =\n (context.config.mode === 'development' && applyDev === caller) ||\n (context.config.mode === 'production' && applyProd === caller)\n if (shouldBuild) {\n context.log('info', `Building ${this.options.name}`)\n await build(this.options.config)\n // context.log('info', 'Done!')\n }\n return true\n }\n\n async watch(): Promise<void> {\n if (this.options.apply?.development === 'serve') {\n // Run \"vite dev\", which starts the app in a local server and\n // refreshes when source files are changed\n const server: ViteDevServer = await createServer(this.options.config)\n await server.listen()\n } else if (this.options.apply?.development === 'watch') {\n // Run \"vite build\" in watch mode so that it rebuilds when source\n // files are changed\n const config: InlineConfig = {\n build: {\n // Enable watch mode\n // TODO: Only do this if not already set up in the given config?\n watch: {}\n },\n ...this.options.config\n }\n await build(config)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,kBAAoC;AAM7B,oBAAoB,SAAoC;AAC7D,SAAO,IAAI,WAAW,OAAO;AAC/B;AAEA,IAAM,aAAN,MAAmC;AAAA,EACjC,YAA6B,SAA4B;AAA5B;AAAA,EAA6B;AAAA,EAE1D,MAAM,aAAa,SAAyC;AAE1D,WAAO,KAAK,cAAc,SAAS,eAAe;AAAA,EACpD;AAAA,EAEA,MAAM,UAAU,SAAyC;AAEvD,WAAO,KAAK,cAAc,SAAS,YAAY;AAAA,EACjD;AAAA,EAEA,MAAc,cAAc,SAAuB,QAA0D;AA1B/G;AA4BI,UAAM,WAAW,YAAK,QAAQ,UAAb,mBAAoB,gBAAe;AACpD,UAAM,YAAY,YAAK,QAAQ,UAAb,mBAAoB,eAAc;AAGpD,UAAM,cACH,QAAQ,OAAO,SAAS,iBAAiB,aAAa,UACtD,QAAQ,OAAO,SAAS,gBAAgB,cAAc;AACzD,QAAI,aAAa;AACf,cAAQ,IAAI,QAAQ,YAAY,KAAK,QAAQ,MAAM;AACnD,YAAM,uBAAM,KAAK,QAAQ,MAAM;AAAA,IAEjC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAuB;AA3C/B;AA4CI,QAAI,YAAK,QAAQ,UAAb,mBAAoB,iBAAgB,SAAS;AAG/C,YAAM,SAAwB,MAAM,8BAAa,KAAK,QAAQ,MAAM;AACpE,YAAM,OAAO,OAAO;AAAA,IACtB,WAAW,YAAK,QAAQ,UAAb,mBAAoB,iBAAgB,SAAS;AAGtD,YAAM,SAAuB;AAAA,QAC3B,OAAO;AAAA,UAGL,OAAO,CAAC;AAAA,QACV;AAAA,SACG,KAAK,QAAQ;AAElB,YAAM,uBAAM,MAAM;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,52 @@
1
+ import { InlineConfig } from 'vite';
2
+ import { Plugin } from '@sdeverywhere/build';
3
+
4
+ interface VitePluginOptions {
5
+ /** The name to include in log messages. */
6
+ name: string;
7
+ /** The Vite config to use. */
8
+ config: InlineConfig;
9
+ /** Specifies the behavior of the plugin for different `sde` build modes. */
10
+ apply?: {
11
+ /**
12
+ * The behavior of the plugin when sde is configured for development mode.
13
+ *
14
+ * If left undefined, defaults to 'post-build'.
15
+ *
16
+ * ```
17
+ * 'skip':
18
+ * Don't run the plugin.
19
+ * 'post-generate':
20
+ * Run "vite build" in the `postGenerate` phase.
21
+ * 'post-build':
22
+ * Run "vite build" in the `postBuild` phase.
23
+ * 'watch':
24
+ * Run "vite build" in the `watch` callback (rebuilds the library when
25
+ * changes are detected in source files); useful for libraries.
26
+ * 'serve':
27
+ * Run "vite dev" (sets up local server and refreshes the app
28
+ * automatically when changes are detected); useful for applications.
29
+ * ```
30
+ */
31
+ development?: 'skip' | 'post-generate' | 'post-build' | 'watch' | 'serve';
32
+ /**
33
+ * The behavior of the plugin when sde is configured for production mode.
34
+ *
35
+ * If left undefined, defaults to 'post-build'.
36
+ *
37
+ * ```
38
+ * 'skip':
39
+ * Don't run the plugin.
40
+ * 'post-generate':
41
+ * Run "vite build" in the `postGenerate` phase.
42
+ * 'post-build':
43
+ * Run "vite build" in the `postBuild` phase.
44
+ * ```
45
+ */
46
+ production?: 'skip' | 'post-generate' | 'post-build';
47
+ };
48
+ }
49
+
50
+ declare function vitePlugin(options: VitePluginOptions): Plugin;
51
+
52
+ export { VitePluginOptions, vitePlugin };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/plugin.ts
19
+ import { build, createServer } from "vite";
20
+ function vitePlugin(options) {
21
+ return new VitePlugin(options);
22
+ }
23
+ var VitePlugin = class {
24
+ constructor(options) {
25
+ this.options = options;
26
+ }
27
+ async postGenerate(context) {
28
+ return this.buildIfNeeded(context, "post-generate");
29
+ }
30
+ async postBuild(context) {
31
+ return this.buildIfNeeded(context, "post-build");
32
+ }
33
+ async buildIfNeeded(context, caller) {
34
+ var _a, _b;
35
+ const applyDev = ((_a = this.options.apply) == null ? void 0 : _a.development) || "post-build";
36
+ const applyProd = ((_b = this.options.apply) == null ? void 0 : _b.production) || "post-build";
37
+ const shouldBuild = context.config.mode === "development" && applyDev === caller || context.config.mode === "production" && applyProd === caller;
38
+ if (shouldBuild) {
39
+ context.log("info", `Building ${this.options.name}`);
40
+ await build(this.options.config);
41
+ }
42
+ return true;
43
+ }
44
+ async watch() {
45
+ var _a, _b;
46
+ if (((_a = this.options.apply) == null ? void 0 : _a.development) === "serve") {
47
+ const server = await createServer(this.options.config);
48
+ await server.listen();
49
+ } else if (((_b = this.options.apply) == null ? void 0 : _b.development) === "watch") {
50
+ const config = __spreadValues({
51
+ build: {
52
+ watch: {}
53
+ }
54
+ }, this.options.config);
55
+ await build(config);
56
+ }
57
+ }
58
+ };
59
+ export {
60
+ vitePlugin
61
+ };
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nimport type { InlineConfig, ViteDevServer } from 'vite'\nimport { build, createServer } from 'vite'\n\nimport type { BuildContext, Plugin } from '@sdeverywhere/build'\n\nimport type { VitePluginOptions } from './options'\n\nexport function vitePlugin(options: VitePluginOptions): Plugin {\n return new VitePlugin(options)\n}\n\nclass VitePlugin implements Plugin {\n constructor(private readonly options: VitePluginOptions) {}\n\n async postGenerate(context: BuildContext): Promise<boolean> {\n // Only build if the plugin is configured to run for 'post-generate'\n return this.buildIfNeeded(context, 'post-generate')\n }\n\n async postBuild(context: BuildContext): Promise<boolean> {\n // Only build if the plugin is configured to run for 'post-build'\n return this.buildIfNeeded(context, 'post-build')\n }\n\n private async buildIfNeeded(context: BuildContext, caller: 'post-generate' | 'post-build'): Promise<boolean> {\n // The apply values default to 'post-build' when left undefined\n const applyDev = this.options.apply?.development || 'post-build'\n const applyProd = this.options.apply?.production || 'post-build'\n\n // Run \"vite build\" only if configured for this mode\n const shouldBuild =\n (context.config.mode === 'development' && applyDev === caller) ||\n (context.config.mode === 'production' && applyProd === caller)\n if (shouldBuild) {\n context.log('info', `Building ${this.options.name}`)\n await build(this.options.config)\n // context.log('info', 'Done!')\n }\n return true\n }\n\n async watch(): Promise<void> {\n if (this.options.apply?.development === 'serve') {\n // Run \"vite dev\", which starts the app in a local server and\n // refreshes when source files are changed\n const server: ViteDevServer = await createServer(this.options.config)\n await server.listen()\n } else if (this.options.apply?.development === 'watch') {\n // Run \"vite build\" in watch mode so that it rebuilds when source\n // files are changed\n const config: InlineConfig = {\n build: {\n // Enable watch mode\n // TODO: Only do this if not already set up in the given config?\n watch: {}\n },\n ...this.options.config\n }\n await build(config)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAGA;AAMO,oBAAoB,SAAoC;AAC7D,SAAO,IAAI,WAAW,OAAO;AAC/B;AAEA,IAAM,aAAN,MAAmC;AAAA,EACjC,YAA6B,SAA4B;AAA5B;AAAA,EAA6B;AAAA,EAE1D,MAAM,aAAa,SAAyC;AAE1D,WAAO,KAAK,cAAc,SAAS,eAAe;AAAA,EACpD;AAAA,EAEA,MAAM,UAAU,SAAyC;AAEvD,WAAO,KAAK,cAAc,SAAS,YAAY;AAAA,EACjD;AAAA,EAEA,MAAc,cAAc,SAAuB,QAA0D;AA1B/G;AA4BI,UAAM,WAAW,YAAK,QAAQ,UAAb,mBAAoB,gBAAe;AACpD,UAAM,YAAY,YAAK,QAAQ,UAAb,mBAAoB,eAAc;AAGpD,UAAM,cACH,QAAQ,OAAO,SAAS,iBAAiB,aAAa,UACtD,QAAQ,OAAO,SAAS,gBAAgB,cAAc;AACzD,QAAI,aAAa;AACf,cAAQ,IAAI,QAAQ,YAAY,KAAK,QAAQ,MAAM;AACnD,YAAM,MAAM,KAAK,QAAQ,MAAM;AAAA,IAEjC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAuB;AA3C/B;AA4CI,QAAI,YAAK,QAAQ,UAAb,mBAAoB,iBAAgB,SAAS;AAG/C,YAAM,SAAwB,MAAM,aAAa,KAAK,QAAQ,MAAM;AACpE,YAAM,OAAO,OAAO;AAAA,IACtB,WAAW,YAAK,QAAQ,UAAb,mBAAoB,iBAAgB,SAAS;AAGtD,YAAM,SAAuB;AAAA,QAC3B,OAAO;AAAA,UAGL,OAAO,CAAC;AAAA,QACV;AAAA,SACG,KAAK,QAAQ;AAElB,YAAM,MAAM,MAAM;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@sdeverywhere/plugin-vite",
3
+ "version": "0.1.0",
4
+ "files": [
5
+ "dist/**"
6
+ ],
7
+ "type": "module",
8
+ "main": "dist/index.cjs",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "dependencies": {
19
+ "@sdeverywhere/build": "^0.1.0",
20
+ "vite": "^2.9.12"
21
+ },
22
+ "author": "Climate Interactive",
23
+ "license": "MIT",
24
+ "homepage": "https://sdeverywhere.org",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/climateinteractive/SDEverywhere.git",
28
+ "directory": "packages/plugin-vite"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/climateinteractive/SDEverywhere/issues"
32
+ },
33
+ "scripts": {
34
+ "clean": "rm -rf dist",
35
+ "lint": "eslint src --ext .ts --max-warnings 0",
36
+ "prettier:check": "prettier --check .",
37
+ "prettier:fix": "prettier --write .",
38
+ "precommit": "../../scripts/precommit",
39
+ "test": "echo No tests yet",
40
+ "test:watch": "echo No tests yet",
41
+ "test:ci": "echo No tests yet",
42
+ "type-check": "tsc --noEmit -p tsconfig-build.json",
43
+ "build": "tsup",
44
+ "ci:build": "run-s clean lint prettier:check test:ci type-check build"
45
+ }
46
+ }