@volley/vwr-loader 1.0.5 → 1.0.6
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/README.md +21 -0
- package/dist/amplitudeFlagFetcher.d.ts +4 -2
- package/dist/amplitudeFlagFetcher.d.ts.map +1 -1
- package/dist/amplitudeFlagFetcher.js +26 -19
- package/dist/amplitudeFlagFetcher.js.map +1 -1
- package/dist/cli.js +234 -0
- package/dist/cli.js.map +1 -0
- package/dist/envDefaults.d.ts +3 -0
- package/dist/envDefaults.d.ts.map +1 -1
- package/dist/envDefaults.js +26 -4
- package/dist/envDefaults.js.map +1 -1
- package/dist/getDeviceId.d.ts +2 -10
- package/dist/getDeviceId.d.ts.map +1 -1
- package/dist/getDeviceId.js +31 -18
- package/dist/getDeviceId.js.map +1 -1
- package/dist/getEnvironment.d.ts +1 -1
- package/dist/getEnvironment.d.ts.map +1 -1
- package/dist/getEnvironment.js +10 -7
- package/dist/getEnvironment.js.map +1 -1
- package/dist/getShellVersion.d.ts +2 -2
- package/dist/getShellVersion.d.ts.map +1 -1
- package/dist/getShellVersion.js +5 -3
- package/dist/getShellVersion.js.map +1 -1
- package/dist/index.html +1 -1
- package/dist/loadVwr.d.ts.map +1 -1
- package/dist/loadVwr.js +8 -6
- package/dist/loadVwr.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/vwrConfig.d.ts +2 -0
- package/dist/vwrConfig.d.ts.map +1 -1
- package/dist/vwrConfig.js +148 -119
- package/dist/vwrConfig.js.map +1 -1
- package/package.json +16 -5
- package/src/amplitudeFlagFetcher.test.ts +36 -59
- package/src/amplitudeFlagFetcher.ts +31 -22
- package/src/envDefaults.ts +33 -4
- package/src/getDeviceId.test.ts +79 -24
- package/src/getDeviceId.ts +47 -22
- package/src/getEnvironment.test.ts +457 -0
- package/src/getEnvironment.ts +12 -9
- package/src/getShellVersion.test.ts +1 -1
- package/src/getShellVersion.ts +7 -3
- package/src/loadVwr.ts +13 -6
- package/src/main.ts +3 -1
- package/src/vite-env.d.ts +3 -0
- package/src/vwrConfig.test.ts +2 -2
- package/src/vwrConfig.ts +202 -199
- package/eslint.config.mjs +0 -23
- package/scripts/build.js +0 -2
- package/scripts/build.ts +0 -207
- package/tsconfig.eslint.json +0 -16
- package/tsconfig.json +0 -17
- package/vite.config.ts +0 -24
- package/vitest.config.ts +0 -8
package/scripts/build.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from "commander"
|
|
3
|
-
import { config as loadDotenv } from "dotenv"
|
|
4
|
-
import fs from "fs-extra"
|
|
5
|
-
import path from "path"
|
|
6
|
-
import { fileURLToPath } from "url"
|
|
7
|
-
import { build } from "vite"
|
|
8
|
-
|
|
9
|
-
import { ENV_DEFAULTS } from "../src/envDefaults.js"
|
|
10
|
-
|
|
11
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
12
|
-
|
|
13
|
-
const program = new Command()
|
|
14
|
-
|
|
15
|
-
// Platforms that support reading environment from native shell at runtime
|
|
16
|
-
// These platforms don't require --env flag (it's optional as an override)
|
|
17
|
-
const NATIVE_ENV_PLATFORMS = ["FIRE_TV", "FIRETV"]
|
|
18
|
-
|
|
19
|
-
program
|
|
20
|
-
.name("build-loader")
|
|
21
|
-
.description("Build vwr-loader with environment configuration")
|
|
22
|
-
.requiredOption(
|
|
23
|
-
"--platform <platform>",
|
|
24
|
-
"Platform: FIRE_TV, SAMSUNG_TV, LG_TV, MOBILE, WEB"
|
|
25
|
-
)
|
|
26
|
-
.option(
|
|
27
|
-
"--env <env>",
|
|
28
|
-
"Environment: local, dev, staging, prod (required for non-Fire TV platforms)"
|
|
29
|
-
)
|
|
30
|
-
.requiredOption("--output <path>", "Output directory")
|
|
31
|
-
.option("--hubUrl <url>", "Override Hub URL")
|
|
32
|
-
.option("--amplitudeKey <key>", "Override Amplitude deployment key")
|
|
33
|
-
.option("--vwrUrl <url>", "Override VWR URL")
|
|
34
|
-
.option("--configUrl <url>", "Override VWR Config URL")
|
|
35
|
-
.option("--configFile <filename>", "Override VWR Config Filename")
|
|
36
|
-
.option("--launchUrl <url>", "Override launch url")
|
|
37
|
-
.parse()
|
|
38
|
-
|
|
39
|
-
const opts = program.opts()
|
|
40
|
-
const normalizedPlatform = opts.platform.toUpperCase()
|
|
41
|
-
const supportsNativeEnv = NATIVE_ENV_PLATFORMS.includes(normalizedPlatform)
|
|
42
|
-
|
|
43
|
-
// Validate --env is provided for platforms that don't support native env reading
|
|
44
|
-
if (!opts.env && !supportsNativeEnv) {
|
|
45
|
-
console.error(
|
|
46
|
-
`❌ --env is required for platform "${opts.platform}"\n` +
|
|
47
|
-
` Only Fire TV can read environment from native shell at runtime.\n` +
|
|
48
|
-
` Valid environments: local, dev, staging, prod`
|
|
49
|
-
)
|
|
50
|
-
process.exit(1)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// For platforms with native env support, log that env will be read at runtime
|
|
54
|
-
if (!opts.env && supportsNativeEnv) {
|
|
55
|
-
console.log(
|
|
56
|
-
`ℹ️ --env not provided. ${opts.platform} will read environment from native shell at runtime.`
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Try to read from shell's .env file (run from shell directory)
|
|
61
|
-
let shellEnv: Record<string, string> = {}
|
|
62
|
-
if (opts.env) {
|
|
63
|
-
const envFile = path.join(process.cwd(), `.env.${opts.env}`)
|
|
64
|
-
if (fs.existsSync(envFile)) {
|
|
65
|
-
console.log(`📄 Reading config from ${envFile}`)
|
|
66
|
-
const result = loadDotenv({ path: envFile })
|
|
67
|
-
shellEnv = result.parsed || {}
|
|
68
|
-
} else {
|
|
69
|
-
console.log(`ℹ️ No .env.${opts.env} found, using defaults/CLI flags`)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Read shell version from package.json (for web shell)
|
|
74
|
-
let shellVersion = "unknown"
|
|
75
|
-
const packageJsonPath = path.join(process.cwd(), "package.json")
|
|
76
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
77
|
-
try {
|
|
78
|
-
const packageJson = JSON.parse(
|
|
79
|
-
fs.readFileSync(packageJsonPath, "utf-8")
|
|
80
|
-
)
|
|
81
|
-
shellVersion = packageJson.version || "unknown"
|
|
82
|
-
} catch {
|
|
83
|
-
console.warn(`⚠️ Could not read version from package.json`)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Get predefined defaults (use "dev" as fallback for config URL defaults when env not specified)
|
|
88
|
-
const envDefaults = opts.env ? ENV_DEFAULTS[opts.env] : undefined
|
|
89
|
-
if (opts.env && !envDefaults) {
|
|
90
|
-
console.error(`❌ Unknown environment: ${opts.env}`)
|
|
91
|
-
console.error(` Valid: local, dev, staging, prod`)
|
|
92
|
-
process.exit(1)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// For Fire TV without --env, use dev defaults for config URLs (actual env comes from native at runtime)
|
|
96
|
-
const fallbackDefaults = ENV_DEFAULTS["dev"]
|
|
97
|
-
|
|
98
|
-
// Config precedence: CLI > shell .env > defaults
|
|
99
|
-
const config = {
|
|
100
|
-
VITE_PLATFORM: normalizedPlatform,
|
|
101
|
-
VITE_ENVIRONMENT: opts.env, // undefined for Fire TV without --env (reads from native)
|
|
102
|
-
VITE_HUB_URL:
|
|
103
|
-
opts.hubUrl ||
|
|
104
|
-
shellEnv.VITE_HUB_URL ||
|
|
105
|
-
envDefaults?.hubUrl ||
|
|
106
|
-
fallbackDefaults.hubUrl,
|
|
107
|
-
VITE_AMPLITUDE_DEPLOYMENT_KEY:
|
|
108
|
-
opts.amplitudeKey ||
|
|
109
|
-
shellEnv.VITE_AMPLITUDE_DEPLOYMENT_KEY ||
|
|
110
|
-
envDefaults?.amplitudeKey ||
|
|
111
|
-
fallbackDefaults.amplitudeKey ||
|
|
112
|
-
"",
|
|
113
|
-
VITE_VWR_URL:
|
|
114
|
-
opts.vwrUrl ||
|
|
115
|
-
shellEnv.VITE_VWR_URL ||
|
|
116
|
-
envDefaults?.vwrUrl ||
|
|
117
|
-
fallbackDefaults.vwrUrl,
|
|
118
|
-
VITE_CONFIG_URL:
|
|
119
|
-
opts.configUrl ||
|
|
120
|
-
shellEnv.VITE_CONFIG_URL ||
|
|
121
|
-
envDefaults?.configUrl ||
|
|
122
|
-
fallbackDefaults.configUrl,
|
|
123
|
-
VITE_CONFIG_FILE:
|
|
124
|
-
opts.configFile ||
|
|
125
|
-
shellEnv.VITE_CONFIG_FILE ||
|
|
126
|
-
envDefaults?.configFile ||
|
|
127
|
-
fallbackDefaults.configFile,
|
|
128
|
-
VITE_LAUNCH_URL:
|
|
129
|
-
opts.launchUrl ||
|
|
130
|
-
shellEnv.VITE_LAUNCH_URL ||
|
|
131
|
-
opts.hubUrl ||
|
|
132
|
-
shellEnv.VITE_HUB_URL ||
|
|
133
|
-
envDefaults?.hubUrl ||
|
|
134
|
-
fallbackDefaults.hubUrl,
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
console.log("🔧 Build configuration:")
|
|
138
|
-
console.log(` Platform: ${config.VITE_PLATFORM}`)
|
|
139
|
-
console.log(
|
|
140
|
-
` Environment: ${config.VITE_ENVIRONMENT ?? "(from native at runtime)"}`
|
|
141
|
-
)
|
|
142
|
-
console.log(` Hub URL: ${config.VITE_HUB_URL}`)
|
|
143
|
-
console.log(` VWR URL: ${config.VITE_VWR_URL}`)
|
|
144
|
-
console.log(
|
|
145
|
-
` Amplitude: ${
|
|
146
|
-
config.VITE_AMPLITUDE_DEPLOYMENT_KEY ? "***" : "(not set)"
|
|
147
|
-
}`
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
// Build with Vite (inline config to avoid path resolution issues)
|
|
151
|
-
const loaderSrcDir = path.join(__dirname, "../src")
|
|
152
|
-
const loaderDistDir = path.join(__dirname, "../dist")
|
|
153
|
-
|
|
154
|
-
// Build define config - VITE_ENVIRONMENT is undefined for Fire TV (reads from native)
|
|
155
|
-
const defineConfig: Record<string, string> = {
|
|
156
|
-
"import.meta.env.VITE_PLATFORM": JSON.stringify(config.VITE_PLATFORM),
|
|
157
|
-
"import.meta.env.VITE_SHELL_VERSION": JSON.stringify(shellVersion),
|
|
158
|
-
"import.meta.env.VITE_HUB_URL": JSON.stringify(config.VITE_HUB_URL),
|
|
159
|
-
"import.meta.env.VITE_AMPLITUDE_DEPLOYMENT_KEY": JSON.stringify(
|
|
160
|
-
config.VITE_AMPLITUDE_DEPLOYMENT_KEY
|
|
161
|
-
),
|
|
162
|
-
"import.meta.env.VITE_VWR_URL": JSON.stringify(config.VITE_VWR_URL),
|
|
163
|
-
"import.meta.env.VITE_CONFIG_URL": JSON.stringify(config.VITE_CONFIG_URL),
|
|
164
|
-
"import.meta.env.VITE_CONFIG_FILE": JSON.stringify(config.VITE_CONFIG_FILE),
|
|
165
|
-
"import.meta.env.VITE_LAUNCH_URL": JSON.stringify(config.VITE_LAUNCH_URL),
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Only inject VITE_ENVIRONMENT if provided (Fire TV reads from native otherwise)
|
|
169
|
-
if (config.VITE_ENVIRONMENT) {
|
|
170
|
-
defineConfig["import.meta.env.VITE_ENVIRONMENT"] = JSON.stringify(
|
|
171
|
-
config.VITE_ENVIRONMENT
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
await build({
|
|
176
|
-
configFile: false,
|
|
177
|
-
root: loaderSrcDir,
|
|
178
|
-
mode: opts.env ?? "production", // Use production mode for minification when env not specified
|
|
179
|
-
build: {
|
|
180
|
-
outDir: loaderDistDir,
|
|
181
|
-
emptyOutDir: true,
|
|
182
|
-
target: "es2017",
|
|
183
|
-
minify: opts.env === "prod" || !opts.env ? "esbuild" : false,
|
|
184
|
-
sourcemap: true,
|
|
185
|
-
rollupOptions: {
|
|
186
|
-
input: {
|
|
187
|
-
main: path.join(loaderSrcDir, "index.html"),
|
|
188
|
-
},
|
|
189
|
-
output: {
|
|
190
|
-
entryFileNames: "[name].js",
|
|
191
|
-
assetFileNames: "[name].[ext]",
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
define: defineConfig,
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
// Copy build output to specified directory
|
|
199
|
-
const distPath = path.join(__dirname, "../dist")
|
|
200
|
-
const outputPath = path.resolve(opts.output)
|
|
201
|
-
|
|
202
|
-
await fs.ensureDir(outputPath)
|
|
203
|
-
await fs.copy(distPath, outputPath, { overwrite: true })
|
|
204
|
-
|
|
205
|
-
console.log(`✅ VWR loader built successfully`)
|
|
206
|
-
console.log(` Output: ${outputPath}`)
|
|
207
|
-
console.log(` Files: index.html, main.js`)
|
package/tsconfig.eslint.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"include": [
|
|
4
|
-
"src/**/*",
|
|
5
|
-
"scripts/**/*",
|
|
6
|
-
"vite.config.ts",
|
|
7
|
-
"vitest.config.ts",
|
|
8
|
-
"**/*.test.ts"
|
|
9
|
-
],
|
|
10
|
-
"exclude": ["node_modules", "dist"],
|
|
11
|
-
"compilerOptions": {
|
|
12
|
-
"noEmit": true,
|
|
13
|
-
"types": ["node", "vite/client", "vitest/globals"]
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2017",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2017", "DOM"],
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"moduleResolution": "bundler"
|
|
14
|
-
},
|
|
15
|
-
"include": ["src/**/*"],
|
|
16
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts", "src/main.ts", "src/index.html"]
|
|
17
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import path from "path"
|
|
2
|
-
import { defineConfig } from "vite"
|
|
3
|
-
|
|
4
|
-
// This config is used by build-loader CLI to build index.html + main.ts
|
|
5
|
-
// The library exports (amplitudeFlagFetcher, getDeviceId) are built by TypeScript
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
root: "./src",
|
|
8
|
-
build: {
|
|
9
|
-
outDir: "../dist",
|
|
10
|
-
emptyOutDir: false, // Keep TypeScript outputs (tsc runs before vite)
|
|
11
|
-
target: "es2017",
|
|
12
|
-
minify: "esbuild",
|
|
13
|
-
sourcemap: true,
|
|
14
|
-
rollupOptions: {
|
|
15
|
-
input: {
|
|
16
|
-
main: path.resolve(__dirname, "src/index.html"),
|
|
17
|
-
},
|
|
18
|
-
output: {
|
|
19
|
-
entryFileNames: "[name].js",
|
|
20
|
-
assetFileNames: "[name].[ext]",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
})
|