@rpcbase/vite 0.113.0 → 0.115.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/dist/dotEnvExpand.d.ts +2 -0
- package/dist/dotEnvExpand.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +566 -0
- package/dist/plugins/posthog-sourcemaps/index.d.ts +8 -0
- package/dist/plugins/posthog-sourcemaps/index.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.input.d.ts +9 -0
- package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.input.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.output.d.ts +8 -0
- package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.output.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.input.d.ts +101 -0
- package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.input.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.output.d.ts +5 -0
- package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.output.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/contact-model.input.d.ts +242 -0
- package/dist/plugins/prune-models-for-client/fixtures/contact-model.input.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/contact-model.output.d.ts +32 -0
- package/dist/plugins/prune-models-for-client/fixtures/contact-model.output.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.input.d.ts +7 -0
- package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.input.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.output.d.ts +5 -0
- package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.output.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.input.d.ts +5 -0
- package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.input.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.output.d.ts +3 -0
- package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.output.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/index.d.ts +3 -0
- package/dist/plugins/prune-models-for-client/index.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/transformSource.d.ts +6 -0
- package/dist/plugins/prune-models-for-client/transformSource.d.ts.map +1 -0
- package/dist/resolveIntegratedPackagePath.d.ts +2 -0
- package/dist/resolveIntegratedPackagePath.d.ts.map +1 -0
- package/package.json +49 -16
- package/index.d.ts +0 -31
- package/index.js +0 -334
- package/src/dotEnvExpand.js +0 -14
- package/src/posthogSourcemapsPlugin.js +0 -76
- package/src/resolveIntegratedPackagePath.js +0 -96
package/index.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import "./src/dotEnvExpand.js"
|
|
2
|
-
|
|
3
|
-
import path from "path"
|
|
4
|
-
import fs from "node:fs"
|
|
5
|
-
|
|
6
|
-
import nocache from "nocache"
|
|
7
|
-
import {
|
|
8
|
-
createServer as viteCreateServer,
|
|
9
|
-
defineConfig,
|
|
10
|
-
mergeConfig,
|
|
11
|
-
loadEnv,
|
|
12
|
-
} from "vite"
|
|
13
|
-
import { viteSingleFile } from "vite-plugin-singlefile"
|
|
14
|
-
import react from "@vitejs/plugin-react"
|
|
15
|
-
import { createHtmlPlugin } from "vite-plugin-html"
|
|
16
|
-
import { glob } from "glob"
|
|
17
|
-
|
|
18
|
-
import { resolveIntegratedPackagePath } from "./src/resolveIntegratedPackagePath.js"
|
|
19
|
-
import { posthogSourcemapsPlugin } from "./src/posthogSourcemapsPlugin.js"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const ensureEnvPolyfillInjectPath = () => {
|
|
23
|
-
const injectDir = path.resolve(process.cwd(), "node_modules/.rpcbase")
|
|
24
|
-
const injectPath = path.join(injectDir, "rb-env-polyfill-inject.js")
|
|
25
|
-
const injectContents = "import \"@rpcbase/env/polyfill\"\n"
|
|
26
|
-
|
|
27
|
-
fs.mkdirSync(injectDir, { recursive: true })
|
|
28
|
-
try {
|
|
29
|
-
const existing = fs.readFileSync(injectPath, "utf8")
|
|
30
|
-
if (existing === injectContents) {
|
|
31
|
-
return injectPath
|
|
32
|
-
}
|
|
33
|
-
} catch {
|
|
34
|
-
// file does not exist yet
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
fs.writeFileSync(injectPath, injectContents, "utf8")
|
|
38
|
-
return injectPath
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const esbuildInjectPath = ensureEnvPolyfillInjectPath()
|
|
42
|
-
const esbuildInject = [esbuildInjectPath]
|
|
43
|
-
const esbuildInjectPlugins = [
|
|
44
|
-
{
|
|
45
|
-
name: "rb-env-polyfill-inject",
|
|
46
|
-
setup(build) {
|
|
47
|
-
build.onResolve({ filter: /.*/ }, (args) => {
|
|
48
|
-
if (args.path === esbuildInjectPath) {
|
|
49
|
-
return { path: esbuildInjectPath, namespace: "file" }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return undefined
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// const isCI = process.env.CI === "true"
|
|
60
|
-
|
|
61
|
-
const isProduction = process.env.NODE_ENV === "production"
|
|
62
|
-
|
|
63
|
-
const ALLOWED_DEV_ENV = ["NODE_ENV", "APP_NAME"]
|
|
64
|
-
// workaround vite.ssrLoadModule not setting ssrBuild properly
|
|
65
|
-
const ALLOWED_ENV_PREFIXES = [
|
|
66
|
-
"RB_PUBLIC_",
|
|
67
|
-
...(isProduction ? [] : ALLOWED_DEV_ENV),
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
// https://github.com/vbenjs/vite-plugin-html?tab=readme-ov-file#minifyoptions
|
|
71
|
-
const htmlMinifyOptions = {
|
|
72
|
-
collapseWhitespace: true,
|
|
73
|
-
keepClosingSlash: true,
|
|
74
|
-
removeComments: false,
|
|
75
|
-
removeRedundantAttributes: true,
|
|
76
|
-
removeScriptTypeAttributes: true,
|
|
77
|
-
removeStyleLinkTypeAttributes: true,
|
|
78
|
-
useShortDoctype: true,
|
|
79
|
-
minifyCSS: true,
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const resolveAliases = {
|
|
83
|
-
"@/api": path.resolve(process.cwd(), "./src/api/"),
|
|
84
|
-
"@/models": path.resolve(process.cwd(), "./src/models/"),
|
|
85
|
-
"@/shared": path.resolve(process.cwd(), "./src/shared/"),
|
|
86
|
-
"@/types": path.resolve(process.cwd(), "./src/types/"),
|
|
87
|
-
"@": path.resolve(process.cwd(), "./src/client/"),
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const integratedPackages = [
|
|
91
|
-
"@hookform/resolvers",
|
|
92
|
-
"axios",
|
|
93
|
-
"events",
|
|
94
|
-
"libphonenumber-js",
|
|
95
|
-
"posthog-js",
|
|
96
|
-
"posthog-js/react",
|
|
97
|
-
"posthog-node",
|
|
98
|
-
"react-router",
|
|
99
|
-
"react-hook-form"
|
|
100
|
-
]
|
|
101
|
-
|
|
102
|
-
// Add each integrated package to resolveAliases
|
|
103
|
-
integratedPackages.forEach(pkg => {
|
|
104
|
-
const resolved = resolveIntegratedPackagePath(pkg)
|
|
105
|
-
resolveAliases[pkg] = resolved
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
resolveAliases["node:events"] = resolveIntegratedPackagePath("events")
|
|
109
|
-
|
|
110
|
-
// Force PostHog React imports to resolve to the ESM bundle to avoid Node ESM
|
|
111
|
-
// directory import errors while keeping SSR compatibility.
|
|
112
|
-
const posthogReactEsm = resolveIntegratedPackagePath("posthog-js/react/dist/esm/index.js")
|
|
113
|
-
resolveAliases["posthog-js/react"] = posthogReactEsm
|
|
114
|
-
resolveAliases["posthog-js/react/dist/esm/index.js"] = posthogReactEsm
|
|
115
|
-
|
|
116
|
-
export {resolveAliases}
|
|
117
|
-
|
|
118
|
-
const rbPackagesNeedingEnvPolyfill = [
|
|
119
|
-
"@rpcbase/auth",
|
|
120
|
-
"@rpcbase/env",
|
|
121
|
-
// "@rpcbase/env/polyfill",
|
|
122
|
-
"@rpcbase/server",
|
|
123
|
-
"@rpcbase/client",
|
|
124
|
-
"@rpcbase/form",
|
|
125
|
-
"@rpcbase/router",
|
|
126
|
-
]
|
|
127
|
-
|
|
128
|
-
const createRuntimeEnv = ({ env, command, mode, isSsrBuild }) => {
|
|
129
|
-
const isDevCommand = command === "serve"
|
|
130
|
-
|
|
131
|
-
const mergedEnv = {
|
|
132
|
-
...env,
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
...mergedEnv,
|
|
137
|
-
BASE_URL: mergedEnv.BASE_URL ?? "/",
|
|
138
|
-
MODE: mode,
|
|
139
|
-
DEV: isDevCommand,
|
|
140
|
-
PROD: !isDevCommand,
|
|
141
|
-
SSR: Boolean(isSsrBuild),
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// https://vite.dev/config/
|
|
146
|
-
const getBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
|
|
147
|
-
const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES)
|
|
148
|
-
const runtimeEnv = createRuntimeEnv({ env, command, mode, isSsrBuild })
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
clearScreen: false,
|
|
152
|
-
plugins: [
|
|
153
|
-
react(),
|
|
154
|
-
createHtmlPlugin({
|
|
155
|
-
// IMPORTANT: minify removes comments by default, which are used by the app ssr
|
|
156
|
-
minify: htmlMinifyOptions,
|
|
157
|
-
}),
|
|
158
|
-
viteSingleFile({
|
|
159
|
-
useRecommendedBuildConfig: false,
|
|
160
|
-
deleteInlinedFiles: true,
|
|
161
|
-
inlinePattern: ["**/*.css"],
|
|
162
|
-
removeViteModuleLoader: false
|
|
163
|
-
}),
|
|
164
|
-
|
|
165
|
-
isProduction && posthogSourcemapsPlugin({}),
|
|
166
|
-
].filter(Boolean),
|
|
167
|
-
define: {
|
|
168
|
-
__vite_env__: runtimeEnv,
|
|
169
|
-
},
|
|
170
|
-
envPrefix: ALLOWED_ENV_PREFIXES,
|
|
171
|
-
publicDir: path.join(process.cwd(), "./src/client/public"),
|
|
172
|
-
build: {
|
|
173
|
-
sourcemap: isProduction ? "hidden" : false,
|
|
174
|
-
cssCodeSplit: false,
|
|
175
|
-
outDir: "./build/dist/",
|
|
176
|
-
rollupOptions: {
|
|
177
|
-
input: {
|
|
178
|
-
app: "./src/client/index.html",
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
commonjsOptions: { transformMixedEsModules: true },
|
|
182
|
-
},
|
|
183
|
-
server: {
|
|
184
|
-
allowedHosts: true,
|
|
185
|
-
headers: {
|
|
186
|
-
"Cache-Control": "no-store",
|
|
187
|
-
},
|
|
188
|
-
watch: {
|
|
189
|
-
ignored: [
|
|
190
|
-
"**/build/playwright/**",
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
resolve: {
|
|
195
|
-
alias: {
|
|
196
|
-
...resolveAliases,
|
|
197
|
-
},
|
|
198
|
-
dedupe: [
|
|
199
|
-
"react", "react-dom",
|
|
200
|
-
"react-router", "react-hook-form"
|
|
201
|
-
],
|
|
202
|
-
preserveSymlinks: true,
|
|
203
|
-
},
|
|
204
|
-
ssr: {
|
|
205
|
-
external: [
|
|
206
|
-
// "react", "react-dom",
|
|
207
|
-
"cookie",
|
|
208
|
-
"mongoose",
|
|
209
|
-
"mongodb",
|
|
210
|
-
],
|
|
211
|
-
noExternal: [
|
|
212
|
-
...rbPackagesNeedingEnvPolyfill,
|
|
213
|
-
// "react-use",
|
|
214
|
-
],
|
|
215
|
-
},
|
|
216
|
-
optimizeDeps: {
|
|
217
|
-
include: [
|
|
218
|
-
// Force RPC Base packages through esbuild so rb-env-polyfill injects before their dist code touches globalThis.__rb_env__
|
|
219
|
-
...rbPackagesNeedingEnvPolyfill,
|
|
220
|
-
"hoist-non-react-statics",
|
|
221
|
-
// "react", "react-dom", "react-dom/server"
|
|
222
|
-
// "cookie"
|
|
223
|
-
],
|
|
224
|
-
exclude: [
|
|
225
|
-
"@radix-ui/*",
|
|
226
|
-
"@rpcbase/ui",
|
|
227
|
-
// TMP only in sample app?
|
|
228
|
-
// "react", "react-dom/server",
|
|
229
|
-
// "react-hook-form",
|
|
230
|
-
// "react-dom"
|
|
231
|
-
],
|
|
232
|
-
esbuildOptions: {
|
|
233
|
-
inject: esbuildInject,
|
|
234
|
-
plugins: esbuildInjectPlugins,
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
// future: {
|
|
238
|
-
// removeSsrLoadModule: true
|
|
239
|
-
// },
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export const extendConfig = (userConfig) => {
|
|
244
|
-
return defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
|
245
|
-
let config
|
|
246
|
-
if (typeof userConfig === "function") {
|
|
247
|
-
config = userConfig({ command, mode, isSsrBuild, isPreview })
|
|
248
|
-
} else {
|
|
249
|
-
config = userConfig
|
|
250
|
-
}
|
|
251
|
-
const baseConfig = getBaseConfig({ command, mode, isSsrBuild, isPreview })
|
|
252
|
-
|
|
253
|
-
return mergeConfig(baseConfig, config)
|
|
254
|
-
})
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const getSpecBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
|
|
258
|
-
const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES)
|
|
259
|
-
const runtimeEnv = createRuntimeEnv({ env, command, mode, isSsrBuild })
|
|
260
|
-
|
|
261
|
-
const input = glob
|
|
262
|
-
.sync("spec/**/*.spec.ts")
|
|
263
|
-
.reduce((inputs, file) => {
|
|
264
|
-
const relativePath = path.relative("spec", file)
|
|
265
|
-
const outputName = relativePath.replace(/\.ts$/, "")
|
|
266
|
-
inputs[outputName] = file
|
|
267
|
-
return inputs
|
|
268
|
-
}, {})
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
clearScreen: false,
|
|
272
|
-
define: {
|
|
273
|
-
__vite_env__: runtimeEnv,
|
|
274
|
-
},
|
|
275
|
-
envPrefix: ALLOWED_ENV_PREFIXES,
|
|
276
|
-
build: {
|
|
277
|
-
outDir: "./build/spec/",
|
|
278
|
-
ssr: true,
|
|
279
|
-
rollupOptions: {
|
|
280
|
-
input,
|
|
281
|
-
},
|
|
282
|
-
commonjsOptions: { transformMixedEsModules: true },
|
|
283
|
-
},
|
|
284
|
-
resolve: {
|
|
285
|
-
alias: {
|
|
286
|
-
...resolveAliases,
|
|
287
|
-
},
|
|
288
|
-
preserveSymlinks: true,
|
|
289
|
-
},
|
|
290
|
-
ssr: {
|
|
291
|
-
external: ["mongoose"],
|
|
292
|
-
noExternal: ["@rpcbase/*"],
|
|
293
|
-
},
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export const extendSpecConfig = (userConfig) => {
|
|
298
|
-
return defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
|
299
|
-
let config
|
|
300
|
-
if (typeof userConfig === "function") {
|
|
301
|
-
config = userConfig({ command, mode, isSsrBuild, isPreview })
|
|
302
|
-
} else {
|
|
303
|
-
config = userConfig
|
|
304
|
-
}
|
|
305
|
-
const baseConfig = getSpecBaseConfig({ command, mode, isSsrBuild, isPreview })
|
|
306
|
-
|
|
307
|
-
return mergeConfig(baseConfig, config)
|
|
308
|
-
})
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
export const createServer = viteCreateServer
|
|
313
|
-
// export const createServer = async (config /* : Record<string, any>*/) => {
|
|
314
|
-
// const env = {
|
|
315
|
-
// command: "serve",
|
|
316
|
-
// mode: process.env.NODE_ENV ?? "development",
|
|
317
|
-
// isSsrBuild: false,
|
|
318
|
-
// isPreview: false,
|
|
319
|
-
// }
|
|
320
|
-
|
|
321
|
-
// const extendedConfig = extendConfig(config)(env)
|
|
322
|
-
// delete extendedConfig.plugins
|
|
323
|
-
|
|
324
|
-
// const viteServer = await viteCreateServer(extendedConfig)
|
|
325
|
-
|
|
326
|
-
// return viteServer
|
|
327
|
-
// }
|
|
328
|
-
|
|
329
|
-
// TODO: I think is is unused, verify and remove if so
|
|
330
|
-
export const disableAppCache = (app) => {
|
|
331
|
-
app.set("etag", false)
|
|
332
|
-
|
|
333
|
-
app.use(nocache())
|
|
334
|
-
}
|
package/src/dotEnvExpand.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import fs from "fs"
|
|
2
|
-
import path from "path"
|
|
3
|
-
|
|
4
|
-
import dotenv from "dotenv"
|
|
5
|
-
import {expand} from "dotenv-expand"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const envFilePath = path.resolve(process.cwd(), ".env")
|
|
9
|
-
|
|
10
|
-
if (fs.existsSync(envFilePath)) {
|
|
11
|
-
const parsedFile = dotenv.parse(fs.readFileSync(envFilePath))
|
|
12
|
-
const expanded = expand({ parsed: parsedFile }).parsed || {}
|
|
13
|
-
Object.assign(process.env, expanded)
|
|
14
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
import fs from "node:fs"
|
|
4
|
-
import { fileURLToPath } from "node:url"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
|
|
9
|
-
function run(bin, args) {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const p = spawn(bin, args, { stdio: "inherit" })
|
|
12
|
-
p.on("close", code => code === 0 ? resolve() : reject(new Error(`posthog-cli exited ${code}`)))
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function resolvePosthogCliBin() {
|
|
17
|
-
const binName = "posthog-cli"
|
|
18
|
-
|
|
19
|
-
const fromCwd = path.join(process.cwd(), "node_modules", ".bin", binName)
|
|
20
|
-
if (fs.existsSync(fromCwd)) return fromCwd
|
|
21
|
-
|
|
22
|
-
let dir = __dirname
|
|
23
|
-
while (true) {
|
|
24
|
-
const candidate = path.join(dir, "node_modules", ".bin", binName)
|
|
25
|
-
if (fs.existsSync(candidate)) return candidate
|
|
26
|
-
|
|
27
|
-
const parent = path.dirname(dir)
|
|
28
|
-
if (parent === dir) break
|
|
29
|
-
dir = parent
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return binName
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function posthogSourcemapsPlugin(opts = {}) {
|
|
36
|
-
const {
|
|
37
|
-
directory = "build/dist",
|
|
38
|
-
version,
|
|
39
|
-
host = process.env.RB_PUBLIC_POSTHOG_HOST || "https://eu.posthog.com",
|
|
40
|
-
deleteAfterUpload = true
|
|
41
|
-
} = opts
|
|
42
|
-
|
|
43
|
-
const bin = resolvePosthogCliBin()
|
|
44
|
-
const globalArgs = ["--host", host]
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
name: "posthog-sourcemaps",
|
|
48
|
-
apply: "build",
|
|
49
|
-
closeBundle: async () => {
|
|
50
|
-
const orange = "\x1b[38;5;208m"
|
|
51
|
-
const reset = "\x1b[0m"
|
|
52
|
-
|
|
53
|
-
const envId = process.env.POSTHOG_CLI_ENV_ID
|
|
54
|
-
const token = process.env.POSTHOG_CLI_TOKEN
|
|
55
|
-
if (!envId || !token) {
|
|
56
|
-
|
|
57
|
-
console.warn(`${orange}posthog-sourcemaps: plugin is enabled but no env vars for auth configured (POSTHOG_CLI_ENV_ID/POSTHOG_CLI_TOKEN). Skipping without failing.${reset}`)
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// if (!process.env.CI) {
|
|
62
|
-
// console.warn(`${orange}posthog-sourcemaps: plugin has correct configuration, but refusing to run when process.env.CI is not set. Skipping without failing.${reset}`)
|
|
63
|
-
// return
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
const injectArgs = ["sourcemap", "inject", "--directory", directory]
|
|
67
|
-
if (version) injectArgs.push("--version", version)
|
|
68
|
-
|
|
69
|
-
const uploadArgs = ["sourcemap", "upload", "--directory", directory]
|
|
70
|
-
if (deleteAfterUpload) uploadArgs.push("--delete-after")
|
|
71
|
-
|
|
72
|
-
await run(bin, [...globalArgs, ...injectArgs])
|
|
73
|
-
await run(bin, [...globalArgs, ...uploadArgs])
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import path from "path"
|
|
2
|
-
import { createRequire } from "module"
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url)
|
|
7
|
-
|
|
8
|
-
const splitPackageSpecifier = (specifier) => {
|
|
9
|
-
if (!specifier) return { pkgName: specifier, subpath: "" }
|
|
10
|
-
|
|
11
|
-
if (specifier.startsWith("@")) {
|
|
12
|
-
const segments = specifier.split("/")
|
|
13
|
-
if (segments.length < 2) return { pkgName: specifier, subpath: "" }
|
|
14
|
-
return {
|
|
15
|
-
pkgName: `${segments[0]}/${segments[1]}`,
|
|
16
|
-
subpath: segments.slice(2).join("/"),
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const [pkgName, ...rest] = specifier.split("/")
|
|
21
|
-
return { pkgName, subpath: rest.join("/") }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const withTrailingSep = p => (p.endsWith(path.sep) ? p : p + path.sep)
|
|
25
|
-
|
|
26
|
-
const resolvePackageRoot = (pkg) => {
|
|
27
|
-
const { pkgName } = splitPackageSpecifier(pkg)
|
|
28
|
-
if (!pkgName) return pkg
|
|
29
|
-
|
|
30
|
-
// 1) chemin rapide: si le package exporte son package.json
|
|
31
|
-
try {
|
|
32
|
-
const pkgJson = require.resolve(`${pkgName}/package.json`)
|
|
33
|
-
return path.dirname(pkgJson)
|
|
34
|
-
} catch (err) {
|
|
35
|
-
// 2) fallback: résoudre l'entrée du package puis remonter jusqu'à sa racine
|
|
36
|
-
const entry = require.resolve(pkgName) // ex: .../node_modules/<pkg>/dist/...
|
|
37
|
-
let dir = path.dirname(entry)
|
|
38
|
-
|
|
39
|
-
// remonter jusqu'à un package.json dont "name" === pkg
|
|
40
|
-
while (true) {
|
|
41
|
-
const pkgJsonPath = path.join(dir, "package.json")
|
|
42
|
-
if (existsSync(pkgJsonPath)) {
|
|
43
|
-
try {
|
|
44
|
-
const json = JSON.parse(readFileSync(pkgJsonPath, "utf8"))
|
|
45
|
-
if (json && json.name === pkgName) return dir
|
|
46
|
-
} catch {
|
|
47
|
-
// ignore parsing errors
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const parent = path.dirname(dir)
|
|
51
|
-
if (parent === dir) break
|
|
52
|
-
dir = parent
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 3) dernier recours: reconstruire depuis le segment node_modules (ok avec pnpm)
|
|
56
|
-
const nmMarker = `${path.sep}node_modules${path.sep}`
|
|
57
|
-
const idx = entry.lastIndexOf(nmMarker)
|
|
58
|
-
if (idx !== -1) {
|
|
59
|
-
const nmRoot = entry.slice(0, idx + nmMarker.length)
|
|
60
|
-
return path.join(nmRoot, pkgName)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// si vraiment rien trouvé, relancer l'erreur d'origine
|
|
64
|
-
throw err
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const resolveIntegratedPackagePath = (specifier) => {
|
|
69
|
-
const { pkgName, subpath } = splitPackageSpecifier(specifier)
|
|
70
|
-
if (!pkgName) return specifier
|
|
71
|
-
|
|
72
|
-
const root = resolvePackageRoot(pkgName)
|
|
73
|
-
if (!subpath) {
|
|
74
|
-
return withTrailingSep(root)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const subDir = path.join(root, subpath)
|
|
78
|
-
const pkgJsonPath = path.join(subDir, "package.json")
|
|
79
|
-
if (existsSync(pkgJsonPath)) {
|
|
80
|
-
try {
|
|
81
|
-
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"))
|
|
82
|
-
const entry = pkgJson.module || pkgJson.main
|
|
83
|
-
if (entry) {
|
|
84
|
-
return path.join(subDir, entry)
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
// ignore parsing errors
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
return require.resolve(specifier)
|
|
93
|
-
} catch {
|
|
94
|
-
return withTrailingSep(subDir)
|
|
95
|
-
}
|
|
96
|
-
}
|