@triggery/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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @triggery/vite
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First public preview release.
|
|
6
|
+
|
|
7
|
+
Vite plugin for Triggery — auto-import every *.trigger.ts file via a virtual module
|
|
8
|
+
|
|
9
|
+
See the [repository-level CHANGELOG](../../CHANGELOG.md#010--2026-05-16) for the full set of packages and the umbrella feature list. Future entries on this file are appended automatically by changesets.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksey Skhomenko
|
|
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,45 @@
|
|
|
1
|
+
# @triggery/vite
|
|
2
|
+
|
|
3
|
+
[Vite](https://vitejs.dev) plugin for [Triggery](https://github.com/triggeryjs/triggery) — auto-import every `*.trigger.ts` file via a virtual module.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @triggery/vite
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vite.config.ts
|
|
15
|
+
import { defineConfig } from 'vite';
|
|
16
|
+
import triggery from '@triggery/vite';
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [triggery({ glob: 'src/**/*.trigger.ts' })],
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then once at the entry point of your app:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// src/main.tsx
|
|
27
|
+
import 'virtual:triggery-registry';
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
That's it — every file matching the glob is auto-imported, so its top-level `createTrigger(...)` call registers with the default runtime.
|
|
31
|
+
|
|
32
|
+
## Options
|
|
33
|
+
|
|
34
|
+
| Option | Default | Description |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| `glob` | `'src/**/*.trigger.{ts,tsx,js,jsx}'` | One pattern or an array. Anything `tinyglobby` accepts. |
|
|
37
|
+
|
|
38
|
+
## HMR
|
|
39
|
+
|
|
40
|
+
* Editing an existing trigger file just re-runs its `createTrigger(...)` — the runtime's last-mount-wins replaces the old registration. No special handling needed.
|
|
41
|
+
* Adding / removing / renaming a trigger file invalidates the virtual module so its import list is rebuilt on the next request.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT © Aleksey Skhomenko
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @triggery/vite — auto-discovery plugin.
|
|
5
|
+
*
|
|
6
|
+
* Add the plugin to `vite.config.ts`, then `import 'virtual:triggery-registry'`
|
|
7
|
+
* once at the entry point of your app. The plugin globs every `*.trigger.ts`
|
|
8
|
+
* file at build time and generates a virtual module that imports all of them,
|
|
9
|
+
* so triggers register themselves with the runtime without manual wiring.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // vite.config.ts
|
|
14
|
+
* import { defineConfig } from 'vite';
|
|
15
|
+
* import triggery from '@triggery/vite';
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({
|
|
18
|
+
* plugins: [triggery({ glob: 'src/**\\/*.trigger.ts' })],
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // src/main.tsx
|
|
22
|
+
* import 'virtual:triggery-registry';
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* HMR: editing an existing trigger file just re-runs its `createTrigger(...)`
|
|
26
|
+
* call — the runtime's last-mount-wins replaces the old registration. Adding
|
|
27
|
+
* or removing a trigger file invalidates the virtual module so its imports
|
|
28
|
+
* list is rebuilt on the next request.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
type TriggeryViteOptions = {
|
|
32
|
+
/** Glob pattern(s) for trigger files. Default: `'src/**\\/*.trigger.{ts,tsx,js,jsx}'`. */
|
|
33
|
+
readonly glob?: string | readonly string[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The plugin factory. Default-exported AND named-exported for convenience.
|
|
37
|
+
*/
|
|
38
|
+
declare function triggery(options?: TriggeryViteOptions): Plugin;
|
|
39
|
+
|
|
40
|
+
export { type TriggeryViteOptions, triggery as default, triggery };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { glob } from 'tinyglobby';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
var VIRTUAL_ID = "virtual:triggery-registry";
|
|
5
|
+
var RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`;
|
|
6
|
+
var DEFAULT_GLOB = "src/**/*.trigger.{ts,tsx,js,jsx}";
|
|
7
|
+
var isTriggerFile = (file) => /\.trigger\.(ts|tsx|js|jsx)$/.test(file);
|
|
8
|
+
function triggery(options = {}) {
|
|
9
|
+
const patterns = options.glob ?? DEFAULT_GLOB;
|
|
10
|
+
let projectRoot = process.cwd();
|
|
11
|
+
return {
|
|
12
|
+
name: "triggery-auto-discovery",
|
|
13
|
+
// Run before user imports so the virtual module is in place at resolution time.
|
|
14
|
+
enforce: "pre",
|
|
15
|
+
configResolved(cfg) {
|
|
16
|
+
projectRoot = cfg.root;
|
|
17
|
+
},
|
|
18
|
+
resolveId(id) {
|
|
19
|
+
if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
|
|
20
|
+
return null;
|
|
21
|
+
},
|
|
22
|
+
async load(id) {
|
|
23
|
+
if (id !== RESOLVED_VIRTUAL_ID) return null;
|
|
24
|
+
const files = await glob(patterns, {
|
|
25
|
+
cwd: projectRoot,
|
|
26
|
+
absolute: true,
|
|
27
|
+
onlyFiles: true
|
|
28
|
+
});
|
|
29
|
+
files.sort();
|
|
30
|
+
const body = files.length === 0 ? "/* @triggery/vite: no *.trigger.* files matched */\n" : `${files.map((f) => `import ${JSON.stringify(f)};`).join("\n")}
|
|
31
|
+
`;
|
|
32
|
+
return `${body}export {};
|
|
33
|
+
`;
|
|
34
|
+
},
|
|
35
|
+
handleHotUpdate(ctx) {
|
|
36
|
+
if (!isTriggerFile(ctx.file)) return;
|
|
37
|
+
const mod = ctx.server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
|
|
38
|
+
if (mod) ctx.server.moduleGraph.invalidateModule(mod);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var index_default = triggery;
|
|
43
|
+
|
|
44
|
+
export { index_default as default, triggery };
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAoCA,IAAM,UAAA,GAAa,2BAAA;AACnB,IAAM,mBAAA,GAAsB,KAAK,UAAU,CAAA,CAAA;AAC3C,IAAM,YAAA,GAAe,kCAAA;AAErB,IAAM,aAAA,GAAgB,CAAC,IAAA,KAA0B,6BAAA,CAA8B,KAAK,IAAI,CAAA;AAKjF,SAAS,QAAA,CAAS,OAAA,GAA+B,EAAC,EAAW;AAClE,EAAA,MAAM,QAAA,GAAW,QAAQ,IAAA,IAAQ,YAAA;AACjC,EAAA,IAAI,WAAA,GAAc,QAAQ,GAAA,EAAI;AAE9B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,yBAAA;AAAA;AAAA,IAEN,OAAA,EAAS,KAAA;AAAA,IACT,eAAe,GAAA,EAAK;AAClB,MAAA,WAAA,GAAc,GAAA,CAAI,IAAA;AAAA,IACpB,CAAA;AAAA,IACA,UAAU,EAAA,EAAI;AACZ,MAAA,IAAI,EAAA,KAAO,YAAY,OAAO,mBAAA;AAC9B,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,MAAM,KAAK,EAAA,EAAI;AACb,MAAA,IAAI,EAAA,KAAO,qBAAqB,OAAO,IAAA;AACvC,MAAA,MAAM,KAAA,GAAQ,MAAM,IAAA,CAAK,QAAA,EAAU;AAAA,QACjC,GAAA,EAAK,WAAA;AAAA,QACL,QAAA,EAAU,IAAA;AAAA,QACV,SAAA,EAAW;AAAA,OACZ,CAAA;AAED,MAAA,KAAA,CAAM,IAAA,EAAK;AACX,MAAA,MAAM,OACJ,KAAA,CAAM,MAAA,KAAW,IACb,sDAAA,GACA,CAAA,EAAG,MAAM,GAAA,CAAI,CAAC,MAAM,CAAA,OAAA,EAAU,IAAA,CAAK,UAAU,CAAC,CAAC,GAAG,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC;AAAA,CAAA;AACpE,MAAA,OAAO,GAAG,IAAI,CAAA;AAAA,CAAA;AAAA,IAChB,CAAA;AAAA,IACA,gBAAgB,GAAA,EAAK;AAKnB,MAAA,IAAI,CAAC,aAAA,CAAc,GAAA,CAAI,IAAI,CAAA,EAAG;AAC9B,MAAA,MAAM,GAAA,GAAM,GAAA,CAAI,MAAA,CAAO,WAAA,CAAY,cAAc,mBAAmB,CAAA;AACpE,MAAA,IAAI,GAAA,EAAK,GAAA,CAAI,MAAA,CAAO,WAAA,CAAY,iBAAiB,GAAG,CAAA;AAAA,IACtD;AAAA,GACF;AACF;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["/**\n * @triggery/vite — auto-discovery plugin.\n *\n * Add the plugin to `vite.config.ts`, then `import 'virtual:triggery-registry'`\n * once at the entry point of your app. The plugin globs every `*.trigger.ts`\n * file at build time and generates a virtual module that imports all of them,\n * so triggers register themselves with the runtime without manual wiring.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import triggery from '@triggery/vite';\n *\n * export default defineConfig({\n * plugins: [triggery({ glob: 'src/**\\\\/*.trigger.ts' })],\n * });\n *\n * // src/main.tsx\n * import 'virtual:triggery-registry';\n * ```\n *\n * HMR: editing an existing trigger file just re-runs its `createTrigger(...)`\n * call — the runtime's last-mount-wins replaces the old registration. Adding\n * or removing a trigger file invalidates the virtual module so its imports\n * list is rebuilt on the next request.\n */\n\nimport { glob } from 'tinyglobby';\nimport type { Plugin } from 'vite';\n\nexport type TriggeryViteOptions = {\n /** Glob pattern(s) for trigger files. Default: `'src/**\\\\/*.trigger.{ts,tsx,js,jsx}'`. */\n readonly glob?: string | readonly string[];\n};\n\nconst VIRTUAL_ID = 'virtual:triggery-registry';\nconst RESOLVED_VIRTUAL_ID = `\\0${VIRTUAL_ID}`;\nconst DEFAULT_GLOB = 'src/**/*.trigger.{ts,tsx,js,jsx}';\n\nconst isTriggerFile = (file: string): boolean => /\\.trigger\\.(ts|tsx|js|jsx)$/.test(file);\n\n/**\n * The plugin factory. Default-exported AND named-exported for convenience.\n */\nexport function triggery(options: TriggeryViteOptions = {}): Plugin {\n const patterns = options.glob ?? DEFAULT_GLOB;\n let projectRoot = process.cwd();\n\n return {\n name: 'triggery-auto-discovery',\n // Run before user imports so the virtual module is in place at resolution time.\n enforce: 'pre',\n configResolved(cfg) {\n projectRoot = cfg.root;\n },\n resolveId(id) {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;\n return null;\n },\n async load(id) {\n if (id !== RESOLVED_VIRTUAL_ID) return null;\n const files = await glob(patterns, {\n cwd: projectRoot,\n absolute: true,\n onlyFiles: true,\n });\n // Sort for deterministic output (helps cache hits + diffability).\n files.sort();\n const body =\n files.length === 0\n ? '/* @triggery/vite: no *.trigger.* files matched */\\n'\n : `${files.map((f) => `import ${JSON.stringify(f)};`).join('\\n')}\\n`;\n return `${body}export {};\\n`;\n },\n handleHotUpdate(ctx) {\n // For new / removed / renamed trigger files we have to rebuild the\n // virtual module's import list. Edits to existing trigger files are\n // already HMR'd by Vite directly — the file's createTrigger call runs\n // again, last-mount-wins replaces the registration.\n if (!isTriggerFile(ctx.file)) return;\n const mod = ctx.server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);\n if (mod) ctx.server.moduleGraph.invalidateModule(mod);\n },\n };\n}\n\nexport default triggery;\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@triggery/vite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin for Triggery — auto-import every *.trigger.ts file via a virtual module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Aleksey Skhomenko",
|
|
7
|
+
"homepage": "https://triggeryjs.github.io/triggery",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/triggeryjs/triggery.git",
|
|
11
|
+
"directory": "packages/vite"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/triggeryjs/triggery/issues",
|
|
14
|
+
"funding": [
|
|
15
|
+
{
|
|
16
|
+
"type": "patreon",
|
|
17
|
+
"url": "https://www.patreon.com/triggery"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"type": "boosty",
|
|
21
|
+
"url": "https://boosty.to/triggery"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"triggery",
|
|
26
|
+
"vite-plugin",
|
|
27
|
+
"auto-discovery",
|
|
28
|
+
"virtual-module",
|
|
29
|
+
"hmr"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"source": "./src/index.ts",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"CHANGELOG.md"
|
|
49
|
+
],
|
|
50
|
+
"sideEffects": false,
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"tinyglobby": "^0.2.10"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"vite": {
|
|
62
|
+
"optional": false
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"tsup": "^8.5.1",
|
|
67
|
+
"typescript": "^6.0.3",
|
|
68
|
+
"vite": "^8.0.13",
|
|
69
|
+
"vitest": "^4.1.6"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsup",
|
|
73
|
+
"dev": "tsup --watch",
|
|
74
|
+
"test": "vitest run --passWithNoTests",
|
|
75
|
+
"test:watch": "vitest --passWithNoTests",
|
|
76
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
77
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
78
|
+
}
|
|
79
|
+
}
|