@ngx-env/builder
Advanced tools
Comparing version 17.2.3 to 17.3.0-alpha.0
@@ -16,5 +16,6 @@ "use strict"; | ||
return (0, rxjs_1.from)((0, project_1.getProjectCwd)(context)).pipe((0, rxjs_1.switchMap)((cwd) => { | ||
const { full, raw } = (0, core_1.env)(Object.assign(Object.assign({}, dotEnvOptions), { cwd, environment: (0, get_environment_1.getEnvironment)(context.target.configuration) })); | ||
const { full, raw } = (0, core_1.env)(Object.assign(Object.assign({}, dotEnvOptions), { cwd, global: "_NGX_ENV_", environment: (0, get_environment_1.getEnvironment)(context.target.configuration) })); | ||
return (0, architect_1.fromAsyncIterable)((0, build_angular_1.buildApplication)(options, context, [(0, esbuild_1.dotenvRunDefine)(full)])).pipe((0, rxjs_1.tap)(() => { | ||
(0, esbuild_index_html_1.indexHtml)((0, path_1.join)(context.workspaceRoot, options.outputPath.toString()), raw, !!options.ssr); | ||
const outputDir = (0, path_1.join)(context.workspaceRoot, options.outputPath.toString()); | ||
(0, esbuild_index_html_1.indexHtml)(outputDir, Array.isArray(options.localize) ? options.localize : [], raw, !!options.ssr, dotEnvOptions.runtime); | ||
})); | ||
@@ -21,0 +22,0 @@ })); |
@@ -16,8 +16,8 @@ "use strict"; | ||
return (0, rxjs_1.from)((0, project_1.getProjectCwd)(context)).pipe((0, rxjs_1.switchMap)((cwd) => { | ||
const { full, raw } = (0, core_1.env)(Object.assign(Object.assign({}, dotEnvOptions), { cwd, environment: (0, get_environment_1.getEnvironment)(context.target.configuration) })); | ||
const { full, raw } = (0, core_1.env)(Object.assign(Object.assign({}, dotEnvOptions), { cwd, global: "_NGX_ENV_", environment: (0, get_environment_1.getEnvironment)(context.target.configuration) })); | ||
return (0, architect_1.fromAsyncIterable)((0, browser_esbuild_1.buildEsbuildBrowser)(options, context, undefined, [ | ||
(0, esbuild_1.dotenvRunDefine)(full), | ||
])).pipe((0, rxjs_1.tap)(() => { | ||
(0, esbuild_index_html_1.indexHtml)((0, path_1.join)(context.workspaceRoot, options.outputPath.toString()), raw, false // no ssr support with browser-esbuild | ||
); | ||
(0, esbuild_index_html_1.indexHtml)((0, path_1.join)(context.workspaceRoot, options.outputPath.toString()), Array.isArray(options.localize) ? options.localize : [], raw, false, // no ssr support with browser-esbuild, | ||
dotEnvOptions.runtime); | ||
})); | ||
@@ -24,0 +24,0 @@ })); |
@@ -41,10 +41,10 @@ "use strict"; | ||
return (0, rxjs_1.combineLatest)([setup(), builderName(), (0, project_1.getProjectCwd)(context)]).pipe((0, rxjs_1.switchMap)(([_options, builderName, cwd]) => { | ||
const ngxEnvOptions = Object.assign(Object.assign(Object.assign({}, options.ngxEnv), _options.ngxEnv), { cwd }); | ||
const dotenvRunOptions = Object.assign(Object.assign(Object.assign({}, options.ngxEnv), _options.ngxEnv), { global: "_NGX_ENV_", cwd }); | ||
if (builderName === "@ngx-env/builder:application") { | ||
options.forceEsbuild = true; | ||
const { full, raw } = (0, core_1.env)(Object.assign(Object.assign({}, ngxEnvOptions), { environment: (0, get_environment_1.getEnvironment)(buildTarget.configuration) })); | ||
const { full, raw } = (0, core_1.env)(Object.assign(Object.assign({}, dotenvRunOptions), { global: "_NGX_ENV_", environment: (0, get_environment_1.getEnvironment)(buildTarget.configuration) })); | ||
delete _options.ngxEnv; | ||
context.getTargetOptions = () => __awaiter(void 0, void 0, void 0, function* () { return _options; }); | ||
return (0, build_angular_1.executeDevServerBuilder)(options, context, { | ||
indexHtml: (content) => __awaiter(void 0, void 0, void 0, function* () { return (0, esbuild_index_html_1.devServerIndexHtml)(content, raw); }), | ||
indexHtml: (content) => __awaiter(void 0, void 0, void 0, function* () { return (0, esbuild_index_html_1.devServerIndexHtml)(content, raw, dotenvRunOptions.runtime); }), | ||
}, { | ||
@@ -56,3 +56,3 @@ buildPlugins: [(0, esbuild_1.dotenvRunDefine)(full)], | ||
else { | ||
return (0, build_angular_1.executeDevServerBuilder)(options, context, (0, webpack_plugin_1.plugin)(ngxEnvOptions)); | ||
return (0, build_angular_1.executeDevServerBuilder)(options, context, (0, webpack_plugin_1.plugin)(dotenvRunOptions)); | ||
} | ||
@@ -59,0 +59,0 @@ })); |
@@ -1,10 +0,4 @@ | ||
export interface NgxEnvOptions { | ||
prefix?: string; | ||
root?: string; | ||
verbose?: boolean; | ||
unsecure?: boolean; | ||
files?: string[]; | ||
} | ||
import { DotenvRunOptions } from "@dotenv-run/core"; | ||
export interface NgxEnvSchema { | ||
ngxEnv?: NgxEnvOptions; | ||
ngxEnv?: DotenvRunOptions; | ||
} |
@@ -566,2 +566,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -568,0 +578,0 @@ "type": "boolean", |
@@ -480,2 +480,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -482,0 +492,0 @@ "type": "boolean", |
@@ -468,2 +468,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -470,0 +480,0 @@ "type": "boolean", |
@@ -123,2 +123,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -125,0 +135,0 @@ "type": "boolean", |
@@ -60,2 +60,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -62,0 +72,0 @@ "type": "boolean", |
@@ -304,2 +304,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -306,0 +316,0 @@ "type": "boolean", |
@@ -15,2 +15,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -17,0 +27,0 @@ "type": "boolean", |
@@ -255,2 +255,12 @@ { | ||
}, | ||
"runtime": { | ||
"type": "boolean", | ||
"description": "Load environment variables at runtime", | ||
"default": false | ||
}, | ||
"define": { | ||
"type": "string", | ||
"description": "Global identifier to access environment variables", | ||
"default": "_NGX_ENV_" | ||
}, | ||
"unsecure": { | ||
@@ -257,0 +267,0 @@ "type": "boolean", |
import { type Dict } from "@dotenv-run/core"; | ||
export declare function indexHtml(outputDir: string, raw: Dict, ssr?: boolean): void; | ||
export declare function devServerIndexHtml(content: string, dict: Dict): string; | ||
export declare function indexHtml(outputDir: string, locales: string[], raw: Dict, ssr?: boolean, runtime?: boolean): void; | ||
export declare function devServerIndexHtml(content: string, raw: Dict, runtime?: boolean): string; |
@@ -7,22 +7,43 @@ "use strict"; | ||
const variables_reducer_1 = require("./variables-reducer"); | ||
function replaceInFile(filePath, raw) { | ||
function indexHtml(outputDir, locales = [], raw, ssr = false, runtime = false) { | ||
try { | ||
const content = (0, fs_1.readFileSync)(filePath, "utf-8"); | ||
(0, fs_1.writeFileSync)(filePath, (0, variables_reducer_1.variablesReducer)(content, raw)); | ||
} | ||
catch (e) { | ||
console.log(`β Failed to replace variables in ${filePath} β`); | ||
throw e; | ||
} | ||
} | ||
function indexHtml(outputDir, raw, ssr = false) { | ||
try { | ||
glob.sync(`${outputDir}/browser/**/*.html`).forEach((filePath) => { | ||
replaceInFile(filePath, raw); | ||
glob.sync(`${outputDir}/browser/**/index.html`).forEach((filePath) => { | ||
const html = (0, fs_1.readFileSync)(filePath, "utf-8"); | ||
const content = (0, variables_reducer_1.variablesReducer)(html, raw); | ||
try { | ||
(0, fs_1.writeFileSync)(filePath, runtime | ||
? content.replace(/<head>/, `<head><script src="/ngx-env.js"></script>`) | ||
: content); | ||
} | ||
catch (e) { | ||
console.log(`β Failed to replace variables in ${filePath} β`); | ||
throw e; | ||
} | ||
}); | ||
if (ssr) { | ||
glob.sync(`${outputDir}/server/**/index.server.html`).forEach((filePath) => { | ||
replaceInFile(filePath, raw); | ||
glob | ||
.sync(`${outputDir}/server/**/index.server.html`) | ||
.forEach((filePath) => { | ||
const html = (0, fs_1.readFileSync)(filePath, "utf-8"); | ||
const content = (0, variables_reducer_1.variablesReducer)(html, raw); | ||
try { | ||
(0, fs_1.writeFileSync)(filePath, content); | ||
} | ||
catch (e) { | ||
console.log(`β Failed to replace variables in ${filePath} β`); | ||
throw e; | ||
} | ||
}); | ||
} | ||
if (runtime) { | ||
const runtimeStmt = `globalThis._NGX_ENV_ = ${JSON.stringify(raw, null, 2)};`; | ||
if (locales.length > 0) { | ||
locales.forEach((locale) => { | ||
(0, fs_1.writeFileSync)(`${outputDir}/browser/${locale}/ngx-env.js`, runtimeStmt); | ||
}); | ||
} | ||
else { | ||
(0, fs_1.writeFileSync)(`${outputDir}/browser/ngx-env.js`, runtimeStmt); | ||
} | ||
} | ||
} | ||
@@ -34,5 +55,8 @@ catch (e) { | ||
exports.indexHtml = indexHtml; | ||
function devServerIndexHtml(content, dict) { | ||
return (0, variables_reducer_1.variablesReducer)(content, dict); | ||
function devServerIndexHtml(content, raw, runtime = false) { | ||
const html = (0, variables_reducer_1.variablesReducer)(content, raw); | ||
return runtime | ||
? html.replace(/<head>/, `<head><script>globalThis._NGX_ENV_ = ${JSON.stringify(raw)}</script>`) | ||
: html; | ||
} | ||
exports.devServerIndexHtml = devServerIndexHtml; |
@@ -1,1 +0,1 @@ | ||
export declare function getEnvironment(configuration: string): string; | ||
export declare function getEnvironment(configuration: string): any; |
@@ -1,51 +0,27 @@ | ||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} | ||
interface ImportMetaEnv { | ||
/** | ||
* Built-in environment variable. | ||
* @see Docs https://github.com/chihab/dotenv-run/packages/angular#node_env. | ||
*/ | ||
// Define the type of the environment variables. | ||
declare interface Env { | ||
readonly NODE_ENV: string; | ||
// Add your environment variables below | ||
// readonly NG_APP_API_URL: string; | ||
// Replace the following with your own environment variables. | ||
// Example: NGX_VERSION: string; | ||
[key: string]: any; | ||
} | ||
/* | ||
* Remove all the deprecated code below if you're using import.meta.env (recommended) | ||
*/ | ||
// Choose how to access the environment variables. | ||
// Remove the unused options. | ||
/****************************** DEPREACTED **************************/ | ||
/** | ||
* @deprecated process.env usage | ||
* prefer using import.meta.env | ||
* */ | ||
// declare var process: { | ||
// env: { | ||
// NODE_ENV: string; | ||
// [key: string]: any; | ||
// }; | ||
// }; | ||
// 1. Use import.meta.env.YOUR_ENV_VAR in your code. (conventional) | ||
declare interface ImportMeta { | ||
readonly env: Env; | ||
} | ||
// If your project references @types/node directly (in you) or indirectly (as in RxJS < 7.6.0), | ||
// you might need to use the following declaration merging. | ||
// declare namespace NodeJS { | ||
// export interface ProcessEnv { | ||
// readonly NODE_ENV: string; | ||
// // Add your environment variables below | ||
// } | ||
// 2. Use _NGX_ENV_.YOUR_ENV_VAR in your code. (customizable) | ||
// You can modify the name of the variable in angular.json. | ||
// ngxEnv: { | ||
// define: '_NGX_ENV_', | ||
// } | ||
declare const _NGX_ENV_: Env; | ||
// If you're using Angular Universal and process.env notation, you'll need to add the following to your tsconfig.server.json: | ||
/* In your tsconfig.server.json */ | ||
// { | ||
// "extends": "./tsconfig.app.json", | ||
// ... | ||
// "exclude": [ | ||
// "src/env.d.ts" | ||
// ] | ||
// } | ||
/*********************************************************************/ | ||
// 3. Use process.env.YOUR_ENV_VAR in your code. (deprecated) | ||
declare namespace NodeJS { | ||
export interface ProcessEnv extends Env {} | ||
} |
{ | ||
"name": "@ngx-env/builder", | ||
"version": "17.2.3", | ||
"version": "17.3.0-alpha.0", | ||
"description": "Easily inject environment variables into your Angular applications", | ||
@@ -19,3 +19,4 @@ "author": "chihab <chihab@gmail.com>", | ||
"collection.json", | ||
"README.md" | ||
"README.md", | ||
"runtime.mjs" | ||
], | ||
@@ -28,3 +29,3 @@ "builders": "builders.json", | ||
"dependencies": { | ||
"@dotenv-run/esbuild": "^1.3.4", | ||
"@dotenv-run/esbuild": "^1.3.5", | ||
"@dotenv-run/webpack": "^1.3.4", | ||
@@ -31,0 +32,0 @@ "glob": "^10.3.10" |
@@ -25,9 +25,7 @@ <h1>@ngx-env/builder</h1> | ||
## Quick Demo | ||
* [v17 with vite/esbuild builder](https://stackblitz.com/edit/ngx-env-3ey8js?file=src%2Fapp.component.ts) | ||
* [v16 with webpack builder](https://stackblitz.com/edit/ngx-env?file=src%2Fapp.component.ts) | ||
- [v17 with vite/esbuild builder](https://stackblitz.com/edit/ngx-env-3ey8js?file=src%2Fapp.component.ts) | ||
- [v16 with webpack builder](https://stackblitz.com/edit/ngx-env?file=src%2Fapp.component.ts) | ||
<h2> Table of contents</h2> | ||
@@ -392,4 +390,2 @@ | ||
You can also checkout the sample Nx workspace [ here](https://github.com/chihab/dotenv-run/packages/angular/tree/main/apps/nx-demo). | ||
# Usage with Docker | ||
@@ -396,0 +392,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172641
47
3672
1
579
Updated@dotenv-run/esbuild@^1.3.5