@vinktarhq/cli 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 +61 -0
- package/LICENSE +21 -0
- package/README.md +378 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/bundler/core.d.ts +140 -0
- package/dist/bundler/core.js +320 -0
- package/dist/bundler/core.js.map +1 -0
- package/dist/bundler/esbuild.d.ts +44 -0
- package/dist/bundler/esbuild.js +85 -0
- package/dist/bundler/esbuild.js.map +1 -0
- package/dist/bundler/rollup.d.ts +84 -0
- package/dist/bundler/rollup.js +221 -0
- package/dist/bundler/rollup.js.map +1 -0
- package/dist/bundler/rspack.d.ts +8 -0
- package/dist/bundler/rspack.js +8 -0
- package/dist/bundler/rspack.js.map +1 -0
- package/dist/bundler/webpack.d.ts +83 -0
- package/dist/bundler/webpack.js +104 -0
- package/dist/bundler/webpack.js.map +1 -0
- package/dist/cjs/bundler/core.d.ts +140 -0
- package/dist/cjs/bundler/core.js +331 -0
- package/dist/cjs/bundler/esbuild.d.ts +44 -0
- package/dist/cjs/bundler/esbuild.js +87 -0
- package/dist/cjs/bundler/rollup.d.ts +84 -0
- package/dist/cjs/bundler/rollup.js +226 -0
- package/dist/cjs/bundler/rspack.d.ts +8 -0
- package/dist/cjs/bundler/rspack.js +12 -0
- package/dist/cjs/bundler/webpack.d.ts +83 -0
- package/dist/cjs/bundler/webpack.js +107 -0
- package/dist/cjs/cli.d.ts +17 -0
- package/dist/cjs/cli.js +358 -0
- package/dist/cjs/commands/doctor.d.ts +15 -0
- package/dist/cjs/commands/doctor.js +134 -0
- package/dist/cjs/commands/inject.d.ts +70 -0
- package/dist/cjs/commands/inject.js +123 -0
- package/dist/cjs/commands/resolve.d.ts +32 -0
- package/dist/cjs/commands/resolve.js +130 -0
- package/dist/cjs/commands/upload.d.ts +74 -0
- package/dist/cjs/commands/upload.js +254 -0
- package/dist/cjs/config.d.ts +51 -0
- package/dist/cjs/config.js +152 -0
- package/dist/cjs/debug-id.d.ts +176 -0
- package/dist/cjs/debug-id.js +323 -0
- package/dist/cjs/discover.d.ts +50 -0
- package/dist/cjs/discover.js +235 -0
- package/dist/cjs/env.d.ts +22 -0
- package/dist/cjs/env.js +52 -0
- package/dist/cjs/glob.d.ts +34 -0
- package/dist/cjs/glob.js +112 -0
- package/dist/cjs/http.d.ts +68 -0
- package/dist/cjs/http.js +211 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/index.js +53 -0
- package/dist/cjs/limits.d.ts +35 -0
- package/dist/cjs/limits.js +38 -0
- package/dist/cjs/multipart.d.ts +28 -0
- package/dist/cjs/multipart.js +44 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/upload.d.ts +178 -0
- package/dist/cjs/upload.js +394 -0
- package/dist/cjs/url.d.ts +25 -0
- package/dist/cjs/url.js +43 -0
- package/dist/cjs/version.d.ts +10 -0
- package/dist/cjs/version.js +13 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.js +354 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/doctor.d.ts +15 -0
- package/dist/commands/doctor.js +132 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/inject.d.ts +70 -0
- package/dist/commands/inject.js +120 -0
- package/dist/commands/inject.js.map +1 -0
- package/dist/commands/resolve.d.ts +32 -0
- package/dist/commands/resolve.js +128 -0
- package/dist/commands/resolve.js.map +1 -0
- package/dist/commands/upload.d.ts +74 -0
- package/dist/commands/upload.js +252 -0
- package/dist/commands/upload.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +150 -0
- package/dist/config.js.map +1 -0
- package/dist/debug-id.d.ts +176 -0
- package/dist/debug-id.js +307 -0
- package/dist/debug-id.js.map +1 -0
- package/dist/discover.d.ts +50 -0
- package/dist/discover.js +229 -0
- package/dist/discover.js.map +1 -0
- package/dist/env.d.ts +22 -0
- package/dist/env.js +50 -0
- package/dist/env.js.map +1 -0
- package/dist/glob.d.ts +34 -0
- package/dist/glob.js +109 -0
- package/dist/glob.js.map +1 -0
- package/dist/http.d.ts +68 -0
- package/dist/http.js +203 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +35 -0
- package/dist/limits.js +36 -0
- package/dist/limits.js.map +1 -0
- package/dist/multipart.d.ts +28 -0
- package/dist/multipart.js +41 -0
- package/dist/multipart.js.map +1 -0
- package/dist/upload.d.ts +178 -0
- package/dist/upload.js +383 -0
- package/dist/upload.js.map +1 -0
- package/dist/url.d.ts +25 -0
- package/dist/url.js +40 -0
- package/dist/url.js.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.js +11 -0
- package/dist/version.js.map +1 -0
- package/dist/vite.d.ts +74 -0
- package/dist/vite.js +166 -0
- package/dist/vite.js.map +1 -0
- package/package.json +141 -0
package/dist/vite.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isAbsolute, join } from 'node:path';
|
|
2
|
+
import { detectRelease, disabled, session } from './bundler/core.js';
|
|
3
|
+
import { repairChunks, stampChunk, writeMaps } from './bundler/rollup.js';
|
|
4
|
+
export function vinktar(options = {}) {
|
|
5
|
+
if (disabled(options))
|
|
6
|
+
return inert();
|
|
7
|
+
let env = {};
|
|
8
|
+
let release = '';
|
|
9
|
+
let outDir = '';
|
|
10
|
+
let base = '/';
|
|
11
|
+
let building = false;
|
|
12
|
+
const tracked = new Map();
|
|
13
|
+
const repaired = new Set();
|
|
14
|
+
let run = null;
|
|
15
|
+
const deleting = options.deleteSourcemapsAfterUpload ?? options.uploadSourcemaps !== false;
|
|
16
|
+
const stamping = options.injectDebugIds !== false;
|
|
17
|
+
return {
|
|
18
|
+
name: 'vinktar',
|
|
19
|
+
async config(rawConfig, rawEnv) {
|
|
20
|
+
const userConfig = rawConfig;
|
|
21
|
+
const { command, mode } = rawEnv;
|
|
22
|
+
// loadEnv is imported lazily so this module stays importable outside a Vite process.
|
|
23
|
+
const { loadEnv } = await import('vite');
|
|
24
|
+
env = loadEnv(mode, userConfig.root ?? process.cwd(), 'VINKTAR_');
|
|
25
|
+
// Only a build needs a release, and resolving one can shell out to git — not something to do
|
|
26
|
+
// on every dev-server start.
|
|
27
|
+
release = options.release ?? (command === 'build' ? detectRelease({ ...process.env, ...env }) : '');
|
|
28
|
+
const define = {
|
|
29
|
+
'import.meta.env.VINKTAR_KEY': JSON.stringify(env['VINKTAR_KEY'] ?? ''),
|
|
30
|
+
'import.meta.env.VINKTAR_HOST': JSON.stringify(env['VINKTAR_HOST'] ?? ''),
|
|
31
|
+
'import.meta.env.VINKTAR_ENVIRONMENT': JSON.stringify(env['VINKTAR_ENVIRONMENT'] ?? ''),
|
|
32
|
+
'import.meta.env.VINKTAR_RELEASE': JSON.stringify(release),
|
|
33
|
+
};
|
|
34
|
+
if (command !== 'build')
|
|
35
|
+
return { define };
|
|
36
|
+
const chosen = userConfig.build?.sourcemap;
|
|
37
|
+
if (chosen === 'inline') {
|
|
38
|
+
console.warn('[vinktar] build.sourcemap is "inline", so the maps are inside the chunks and cannot be uploaded. Use true or "hidden".');
|
|
39
|
+
return { define };
|
|
40
|
+
}
|
|
41
|
+
if (chosen === false) {
|
|
42
|
+
console.warn('[vinktar] build.sourcemap is false, so there is nothing to upload and no frame will resolve.');
|
|
43
|
+
return { define };
|
|
44
|
+
}
|
|
45
|
+
// 'hidden': maps exist for the upload, chunks carry no sourceMappingURL comment. Forced over
|
|
46
|
+
// an explicit `true` only while the maps are being deleted afterwards — a comment pointing at
|
|
47
|
+
// a file that is about to be removed is a 404 in every devtools session. Keep the maps
|
|
48
|
+
// (`deleteSourcemapsAfterUpload: false`) and `true` is left exactly as configured.
|
|
49
|
+
if (chosen === undefined || (chosen === true && deleting)) {
|
|
50
|
+
return { define, build: { sourcemap: 'hidden' } };
|
|
51
|
+
}
|
|
52
|
+
return { define };
|
|
53
|
+
},
|
|
54
|
+
configResolved(raw) {
|
|
55
|
+
const resolved = raw;
|
|
56
|
+
building = resolved.command === 'build';
|
|
57
|
+
base = resolved.base;
|
|
58
|
+
outDir = isAbsolute(resolved.build.outDir) ? resolved.build.outDir : join(resolved.root, resolved.build.outDir);
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* A watch rebuild can land on a different commit than the one the process started on, and a
|
|
62
|
+
* stale release is worse than none: the maps go up under a name the running application does
|
|
63
|
+
* not report. Cheap enough to redo — one `git rev-parse`, and only when nothing pinned it.
|
|
64
|
+
*/
|
|
65
|
+
buildStart() {
|
|
66
|
+
if (!building)
|
|
67
|
+
return;
|
|
68
|
+
tracked.clear();
|
|
69
|
+
repaired.clear();
|
|
70
|
+
if (options.release === undefined && (env['VINKTAR_RELEASE'] ?? '') === '') {
|
|
71
|
+
release = detectRelease({ ...process.env, ...env });
|
|
72
|
+
}
|
|
73
|
+
run = session({ urlPrefix: base, ...options, release }, { ...process.env, ...env });
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* `order: 'post'` is load-bearing, not tidiness.
|
|
77
|
+
*
|
|
78
|
+
* Minification is itself a `renderChunk` hook, and esbuild strips any comment that is not
|
|
79
|
+
* `sourceMappingURL`. Running before it meant the `//# debugId=` line was deleted on every
|
|
80
|
+
* minified build, so the uploader could not read the id back — it re-derived one from the
|
|
81
|
+
* minified bytes instead and filed the map under an id no stack frame would ever report.
|
|
82
|
+
* Running last means the id is stamped into the final bytes, and still before Rollup computes
|
|
83
|
+
* the content hash in the filename.
|
|
84
|
+
*/
|
|
85
|
+
renderChunk: {
|
|
86
|
+
order: 'post',
|
|
87
|
+
handler(code, chunk) {
|
|
88
|
+
if (!building || !stamping)
|
|
89
|
+
return null;
|
|
90
|
+
return stampChunk(code, chunk, tracked, this);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Shift each map by the line the snippet took, and restore the comment the minifier stripped.
|
|
95
|
+
*
|
|
96
|
+
* `order: 'pre'` because Vite's own `vite:build-import-analysis` runs here too, and it
|
|
97
|
+
* re-combines the entry chunk's map with one measured against the code INCLUDING our line.
|
|
98
|
+
* Handing it a map that is a line short collapses that chunk's mappings to nothing.
|
|
99
|
+
*/
|
|
100
|
+
generateBundle: {
|
|
101
|
+
order: 'pre',
|
|
102
|
+
handler(_options, bundle) {
|
|
103
|
+
if (!building)
|
|
104
|
+
return;
|
|
105
|
+
repairChunks(bundle, tracked);
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* `writeBundle`, not `closeBundle`, because it is handed the output options — and the output
|
|
110
|
+
* directory is not always Vite's `build.outDir`. A config that sets
|
|
111
|
+
* `rollupOptions.output.dir` (a theme extension writing straight into `assets/`, say) leaves
|
|
112
|
+
* `build.outDir` at its default, so scanning that found an empty or missing directory and
|
|
113
|
+
* uploaded nothing, silently, on every build.
|
|
114
|
+
*
|
|
115
|
+
* Called once per output, and every one of them is uploaded. The previous version latched on
|
|
116
|
+
* the directory and returned early for the rest, so `@vitejs/plugin-legacy`'s second output —
|
|
117
|
+
* the chunks actually served to the browsers most likely to produce an unreadable stack — was
|
|
118
|
+
* never sent.
|
|
119
|
+
*/
|
|
120
|
+
async writeBundle(rawOptions, bundle) {
|
|
121
|
+
if (!building)
|
|
122
|
+
return;
|
|
123
|
+
const dir = directoryOf(rawOptions) || outDir;
|
|
124
|
+
if (dir === '')
|
|
125
|
+
return;
|
|
126
|
+
// The maps are written again from the bundle, because Rollup emits a chunk's map from the
|
|
127
|
+
// reference it captured while rendering — an edit made in `generateBundle` reaches every
|
|
128
|
+
// other plugin and never reaches the file.
|
|
129
|
+
await writeMaps(dir, bundle, tracked, repaired);
|
|
130
|
+
// `buildStart` normally creates it; a plugin added to an already-running build might not
|
|
131
|
+
// have seen that hook, and an upload that silently does not happen is the whole problem.
|
|
132
|
+
run ??= session({ urlPrefix: base, ...options, release }, { ...process.env, ...env });
|
|
133
|
+
await run.upload(dir);
|
|
134
|
+
await run.cleanup();
|
|
135
|
+
},
|
|
136
|
+
async closeBundle() {
|
|
137
|
+
await run?.cleanup();
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The plugin that does nothing, for `disable: true`.
|
|
143
|
+
*
|
|
144
|
+
* Vite configs are reused by vitest and Storybook, and both would otherwise pay for `loadEnv`, a
|
|
145
|
+
* `git rev-parse` and a walk of a directory they never built.
|
|
146
|
+
*/
|
|
147
|
+
function inert() {
|
|
148
|
+
return {
|
|
149
|
+
name: 'vinktar',
|
|
150
|
+
config: async () => ({ define: {} }),
|
|
151
|
+
configResolved: () => { },
|
|
152
|
+
buildStart: () => { },
|
|
153
|
+
renderChunk: { order: 'post', handler: () => null },
|
|
154
|
+
generateBundle: { order: 'pre', handler: () => { } },
|
|
155
|
+
writeBundle: async () => { },
|
|
156
|
+
closeBundle: async () => { },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Rollup's own output directory, which is the one the files were actually written to. */
|
|
160
|
+
function directoryOf(rawOptions) {
|
|
161
|
+
const dir = rawOptions?.dir;
|
|
162
|
+
if (typeof dir !== 'string' || dir === '')
|
|
163
|
+
return '';
|
|
164
|
+
return isAbsolute(dir) ? dir : join(process.cwd(), dir);
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAqC,MAAM,mBAAmB,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAmB,MAAM,qBAAqB,CAAC;AAgF3F,MAAM,UAAU,OAAO,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AC;AAED,0FAA0F;AAC1F,SAAS,WAAW,CAAC,UAAmB;IACtC,MAAM,GAAG,GAAI,UAAuC,EAAE,GAAG,CAAC;IAC1D,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAErD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { isAbsolute, join } from 'node:path';\n\nimport { detectRelease, disabled, session, type BundlerOptions, type Session } from './bundler/core.js';\nimport { repairChunks, stampChunk, writeMaps, type ChunkStamp } from './bundler/rollup.js';\n\n/**\n * The plugin's shape, declared here rather than imported as Vite's `Plugin`.\n *\n * Two copies of Vite's types at different patch versions — the consumer's and this package's —\n * are structurally identical and nominally incompatible, so importing `Plugin` makes\n * `plugins: [vinktar()]` fail to typecheck for anyone whose lockfile resolves a different patch\n * than ours. Structural typing has no such problem, and it also means this package's public types\n * do not depend on `vite` at all.\n */\nexport interface VitePlugin {\n name: string;\n /**\n * `unknown` parameters, deliberately, and it is the direction that matters: a hook which accepts\n * ANYTHING can stand in for one Vite will call with its own config types, whatever version those\n * come from. A hook typed against a narrower shape cannot — which is the whole failure this\n * exists to avoid, and `never` (the first thing that looks right) has exactly the wrong variance.\n */\n config(userConfig: unknown, env: unknown): Promise<{\n define: Record<string, string>;\n build?: { sourcemap: 'hidden' };\n }>;\n configResolved(resolved: unknown): void;\n buildStart(): void;\n renderChunk: {\n order: 'post';\n handler(this: unknown, code: string, chunk: unknown): { code: string; map: null } | null;\n };\n generateBundle: { order: 'pre'; handler(options: unknown, bundle: Record<string, unknown>): void };\n writeBundle(options: unknown, bundle: Record<string, unknown>): Promise<void>;\n closeBundle(): Promise<void>;\n}\n\n/** What the plugin actually reads out of Vite's config, and nothing more. */\ninterface UserConfigShape {\n root?: string | undefined;\n build?: { sourcemap?: unknown } | undefined;\n}\n\ninterface ResolvedConfigShape {\n command: string;\n base: string;\n root: string;\n build: { outDir: string };\n}\n\n/**\n * The Vite side of Vinktar, as one plugin.\n *\n * ```ts\n * // vite.config.ts\n * import { vinktar } from '@vinktarhq/cli/vite';\n *\n * export default defineConfig({ plugins: [vinktar()] });\n * ```\n *\n * What it does, all driven by the same VINKTAR_* variables every other Vinktar SDK reads\n * (from the process env and Vite's .env files):\n *\n * - Exposes `import.meta.env.VINKTAR_KEY`, `VINKTAR_HOST`, `VINKTAR_ENVIRONMENT` and\n * `VINKTAR_RELEASE` to the bundle, so `init({ key: import.meta.env.VINKTAR_KEY, … })` is the\n * whole application-side setup. `VINKTAR_CLI_KEY` is NEVER exposed — a bundle is public.\n * - `VINKTAR_RELEASE` falls back to the CI commit, then the git SHA, so errors correlate to a\n * deploy without anyone wiring a release string.\n * - Turns on `build.sourcemap: 'hidden'`.\n * - Stamps a debug id into each chunk **as it is rendered**, then after the build uploads the maps\n * under the same release the bundle reports, and removes them from the output directory.\n *\n * ## Why injection is a `renderChunk` hook\n *\n * The previous version rewrote the files in `closeBundle`, after Vite had already written them.\n * That is after Rollup computed the content hash in each filename, after `vite-plugin-pwa` wrote\n * its precache revisions, and after any integrity or precompression plugin had run — so every one\n * of those recorded a hash of bytes that no longer existed on disk. A service worker built that\n * way serves a permanently stale chunk. Injecting during `renderChunk` makes the snippet part of\n * the artifact everything downstream measures.\n */\nexport interface VinktarPluginOptions extends BundlerOptions {}\n\nexport function vinktar(options: VinktarPluginOptions = {}): VitePlugin {\n if (disabled(options)) return inert();\n\n let env: Record<string, string> = {};\n let release = '';\n let outDir = '';\n let base = '/';\n let building = false;\n const tracked = new Map<string, ChunkStamp>();\n const repaired = new Set<string>();\n let run: Session | null = null;\n\n const deleting = options.deleteSourcemapsAfterUpload ?? options.uploadSourcemaps !== false;\n const stamping = options.injectDebugIds !== false;\n\n return {\n name: 'vinktar',\n\n async config(rawConfig: unknown, rawEnv: unknown) {\n const userConfig = rawConfig as UserConfigShape;\n const { command, mode } = rawEnv as { command: string; mode: string };\n\n // loadEnv is imported lazily so this module stays importable outside a Vite process.\n const { loadEnv } = await import('vite');\n env = loadEnv(mode, userConfig.root ?? process.cwd(), 'VINKTAR_');\n // Only a build needs a release, and resolving one can shell out to git — not something to do\n // on every dev-server start.\n release = options.release ?? (command === 'build' ? detectRelease({ ...process.env, ...env }) : '');\n\n const define = {\n 'import.meta.env.VINKTAR_KEY': JSON.stringify(env['VINKTAR_KEY'] ?? ''),\n 'import.meta.env.VINKTAR_HOST': JSON.stringify(env['VINKTAR_HOST'] ?? ''),\n 'import.meta.env.VINKTAR_ENVIRONMENT': JSON.stringify(env['VINKTAR_ENVIRONMENT'] ?? ''),\n 'import.meta.env.VINKTAR_RELEASE': JSON.stringify(release),\n };\n\n if (command !== 'build') return { define };\n\n const chosen = userConfig.build?.sourcemap;\n\n if (chosen === 'inline') {\n console.warn(\n '[vinktar] build.sourcemap is \"inline\", so the maps are inside the chunks and cannot be uploaded. Use true or \"hidden\".',\n );\n\n return { define };\n }\n\n if (chosen === false) {\n console.warn('[vinktar] build.sourcemap is false, so there is nothing to upload and no frame will resolve.');\n\n return { define };\n }\n\n // 'hidden': maps exist for the upload, chunks carry no sourceMappingURL comment. Forced over\n // an explicit `true` only while the maps are being deleted afterwards — a comment pointing at\n // a file that is about to be removed is a 404 in every devtools session. Keep the maps\n // (`deleteSourcemapsAfterUpload: false`) and `true` is left exactly as configured.\n if (chosen === undefined || (chosen === true && deleting)) {\n return { define, build: { sourcemap: 'hidden' as const } };\n }\n\n return { define };\n },\n\n configResolved(raw: unknown) {\n const resolved = raw as ResolvedConfigShape;\n\n building = resolved.command === 'build';\n base = resolved.base;\n outDir = isAbsolute(resolved.build.outDir) ? resolved.build.outDir : join(resolved.root, resolved.build.outDir);\n },\n\n /**\n * A watch rebuild can land on a different commit than the one the process started on, and a\n * stale release is worse than none: the maps go up under a name the running application does\n * not report. Cheap enough to redo — one `git rev-parse`, and only when nothing pinned it.\n */\n buildStart() {\n if (!building) return;\n\n tracked.clear();\n repaired.clear();\n if (options.release === undefined && (env['VINKTAR_RELEASE'] ?? '') === '') {\n release = detectRelease({ ...process.env, ...env });\n }\n run = session({ urlPrefix: base, ...options, release }, { ...process.env, ...env });\n },\n\n /**\n * `order: 'post'` is load-bearing, not tidiness.\n *\n * Minification is itself a `renderChunk` hook, and esbuild strips any comment that is not\n * `sourceMappingURL`. Running before it meant the `//# debugId=` line was deleted on every\n * minified build, so the uploader could not read the id back — it re-derived one from the\n * minified bytes instead and filed the map under an id no stack frame would ever report.\n * Running last means the id is stamped into the final bytes, and still before Rollup computes\n * the content hash in the filename.\n */\n renderChunk: {\n order: 'post',\n handler(this: unknown, code: string, chunk: unknown) {\n if (!building || !stamping) return null;\n\n return stampChunk(code, chunk, tracked, this);\n },\n },\n\n /**\n * Shift each map by the line the snippet took, and restore the comment the minifier stripped.\n *\n * `order: 'pre'` because Vite's own `vite:build-import-analysis` runs here too, and it\n * re-combines the entry chunk's map with one measured against the code INCLUDING our line.\n * Handing it a map that is a line short collapses that chunk's mappings to nothing.\n */\n generateBundle: {\n order: 'pre',\n handler(_options: unknown, bundle: Record<string, unknown>) {\n if (!building) return;\n\n repairChunks(bundle, tracked);\n },\n },\n\n /**\n * `writeBundle`, not `closeBundle`, because it is handed the output options — and the output\n * directory is not always Vite's `build.outDir`. A config that sets\n * `rollupOptions.output.dir` (a theme extension writing straight into `assets/`, say) leaves\n * `build.outDir` at its default, so scanning that found an empty or missing directory and\n * uploaded nothing, silently, on every build.\n *\n * Called once per output, and every one of them is uploaded. The previous version latched on\n * the directory and returned early for the rest, so `@vitejs/plugin-legacy`'s second output —\n * the chunks actually served to the browsers most likely to produce an unreadable stack — was\n * never sent.\n */\n async writeBundle(rawOptions: unknown, bundle: Record<string, unknown>) {\n if (!building) return;\n\n const dir = directoryOf(rawOptions) || outDir;\n if (dir === '') return;\n\n // The maps are written again from the bundle, because Rollup emits a chunk's map from the\n // reference it captured while rendering — an edit made in `generateBundle` reaches every\n // other plugin and never reaches the file.\n await writeMaps(dir, bundle, tracked, repaired);\n\n // `buildStart` normally creates it; a plugin added to an already-running build might not\n // have seen that hook, and an upload that silently does not happen is the whole problem.\n run ??= session({ urlPrefix: base, ...options, release }, { ...process.env, ...env });\n\n await run.upload(dir);\n await run.cleanup();\n },\n\n async closeBundle() {\n await run?.cleanup();\n },\n };\n}\n\n/**\n * The plugin that does nothing, for `disable: true`.\n *\n * Vite configs are reused by vitest and Storybook, and both would otherwise pay for `loadEnv`, a\n * `git rev-parse` and a walk of a directory they never built.\n */\nfunction inert(): VitePlugin {\n return {\n name: 'vinktar',\n config: async () => ({ define: {} }),\n configResolved: () => {},\n buildStart: () => {},\n renderChunk: { order: 'post', handler: () => null },\n generateBundle: { order: 'pre', handler: () => {} },\n writeBundle: async () => {},\n closeBundle: async () => {},\n };\n}\n\n/** Rollup's own output directory, which is the one the files were actually written to. */\nfunction directoryOf(rawOptions: unknown): string {\n const dir = (rawOptions as { dir?: unknown } | null)?.dir;\n if (typeof dir !== 'string' || dir === '') return '';\n\n return isAbsolute(dir) ? dir : join(process.cwd(), dir);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vinktarhq/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vinktar CLI: upload source maps so stack traces resolve to your original code.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vinktar",
|
|
7
|
+
"sourcemaps",
|
|
8
|
+
"error-tracking",
|
|
9
|
+
"cli"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://vinktar.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/vinktarhq/cli/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/vinktarhq/cli.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "john.vink",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/cjs/index.d.ts",
|
|
30
|
+
"default": "./dist/cjs/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"./vite": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/vite.d.ts",
|
|
36
|
+
"default": "./dist/vite.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./rollup": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/bundler/rollup.d.ts",
|
|
42
|
+
"default": "./dist/bundler/rollup.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/cjs/bundler/rollup.d.ts",
|
|
46
|
+
"default": "./dist/cjs/bundler/rollup.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./webpack": {
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/bundler/webpack.d.ts",
|
|
52
|
+
"default": "./dist/bundler/webpack.js"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/cjs/bundler/webpack.d.ts",
|
|
56
|
+
"default": "./dist/cjs/bundler/webpack.js"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"./rspack": {
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./dist/bundler/rspack.d.ts",
|
|
62
|
+
"default": "./dist/bundler/rspack.js"
|
|
63
|
+
},
|
|
64
|
+
"require": {
|
|
65
|
+
"types": "./dist/cjs/bundler/rspack.d.ts",
|
|
66
|
+
"default": "./dist/cjs/bundler/rspack.js"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"./esbuild": {
|
|
70
|
+
"import": {
|
|
71
|
+
"types": "./dist/bundler/esbuild.d.ts",
|
|
72
|
+
"default": "./dist/bundler/esbuild.js"
|
|
73
|
+
},
|
|
74
|
+
"require": {
|
|
75
|
+
"types": "./dist/cjs/bundler/esbuild.d.ts",
|
|
76
|
+
"default": "./dist/cjs/bundler/esbuild.js"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"main": "./dist/index.js",
|
|
81
|
+
"types": "./dist/index.d.ts",
|
|
82
|
+
"bin": {
|
|
83
|
+
"vinktar": "dist/bin.js"
|
|
84
|
+
},
|
|
85
|
+
"files": [
|
|
86
|
+
"dist",
|
|
87
|
+
"README.md",
|
|
88
|
+
"CHANGELOG.md",
|
|
89
|
+
"LICENSE"
|
|
90
|
+
],
|
|
91
|
+
"scripts": {
|
|
92
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/postbuild.mjs",
|
|
93
|
+
"prepack": "npm run build",
|
|
94
|
+
"prepublishOnly": "npm test && npm run test:bundlers",
|
|
95
|
+
"test": "vitest run",
|
|
96
|
+
"test:bundlers": "vitest run --config vitest.bundlers.config.ts",
|
|
97
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
98
|
+
},
|
|
99
|
+
"devDependencies": {
|
|
100
|
+
"@rspack/core": "^1.6.0",
|
|
101
|
+
"@types/node": "^24.0.0",
|
|
102
|
+
"esbuild": "^0.28.2",
|
|
103
|
+
"rollup": "^4.63.1",
|
|
104
|
+
"typescript": "^5.6.0",
|
|
105
|
+
"vite": "^7.3.6",
|
|
106
|
+
"vite8": "npm:vite@^8",
|
|
107
|
+
"vitest": "^3.0.0",
|
|
108
|
+
"webpack": "^5.110.1"
|
|
109
|
+
},
|
|
110
|
+
"peerDependencies": {
|
|
111
|
+
"@rspack/core": ">=1",
|
|
112
|
+
"esbuild": ">=0.19",
|
|
113
|
+
"rollup": ">=3",
|
|
114
|
+
"vite": ">=5",
|
|
115
|
+
"webpack": ">=5"
|
|
116
|
+
},
|
|
117
|
+
"peerDependenciesMeta": {
|
|
118
|
+
"@rspack/core": {
|
|
119
|
+
"optional": true
|
|
120
|
+
},
|
|
121
|
+
"esbuild": {
|
|
122
|
+
"optional": true
|
|
123
|
+
},
|
|
124
|
+
"rollup": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"vite": {
|
|
128
|
+
"optional": true
|
|
129
|
+
},
|
|
130
|
+
"webpack": {
|
|
131
|
+
"optional": true
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"engines": {
|
|
135
|
+
"node": ">=18"
|
|
136
|
+
},
|
|
137
|
+
"publishConfig": {
|
|
138
|
+
"access": "public",
|
|
139
|
+
"provenance": true
|
|
140
|
+
}
|
|
141
|
+
}
|