Skip to content

Commit b169a21

Browse files
authored
feat: add runtime support (#93)
1 parent 96ab4c1 commit b169a21

34 files changed

+1886
-327
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.DS_Store
44
node_modules
55
dist
6+
tmp

examples/.verdaccio/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# path to a directory with all packages
2+
storage: ../tmp/local-registry/storage
3+
4+
# a list of other known repositories we can talk to
5+
uplinks:
6+
npmjs:
7+
url: https://registry.npmjs.org/
8+
maxage: 60m
9+
10+
packages:
11+
"**":
12+
# give all users (including non-authenticated users) full access
13+
# because it is a local registry
14+
access: $all
15+
publish: $all
16+
unpublish: $all
17+
18+
# if package is not available locally, proxy requests to npm registry
19+
proxy: npmjs
20+
21+
# log settings
22+
logs:
23+
type: stdout
24+
format: pretty
25+
level: warn
26+
27+
publish:
28+
allow_offline: true # set offline to true to allow publish offline

examples/apps/ng-app-cli/angular.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
"browser": "src/main.ts",
2828
"localize": ["fr"],
2929
"i18nMissingTranslation": "error",
30-
"polyfills": ["zone.js", "src/polyfills.ts"],
30+
"polyfills": ["zone.js"],
3131
"tsConfig": "tsconfig.app.json",
3232
"ngxEnv": {
3333
"prefix": "NGX_",
34+
"verbose": true,
3435
"unsecure": true,
36+
"runtime": true,
3537
"files": [".env.app", ".env"]
3638
},
3739
"assets": ["src/favicon.ico", "src/assets"],
@@ -74,7 +76,7 @@
7476
"main": "src/main.ts",
7577
"localize": ["fr"],
7678
"i18nMissingTranslation": "error",
77-
"polyfills": ["zone.js", "src/polyfills.ts"],
79+
"polyfills": ["zone.js"],
7880
"tsConfig": "tsconfig.app.json",
7981
"ngxEnv": {
8082
"prefix": "NGX_",
@@ -117,7 +119,7 @@
117119
"main": "src/main.ts",
118120
"localize": ["fr"],
119121
"i18nMissingTranslation": "error",
120-
"polyfills": ["zone.js", "src/polyfills.ts"],
122+
"polyfills": ["zone.js"],
121123
"tsConfig": "tsconfig.app.json",
122124
"ngxEnv": {
123125
"prefix": "NGX_",
@@ -185,7 +187,7 @@
185187
"test": {
186188
"builder": "@ngx-env/builder:karma",
187189
"options": {
188-
"polyfills": ["zone.js", "zone.js/testing", "src/polyfills.ts"],
190+
"polyfills": ["zone.js", "zone.js/testing"],
189191
"tsConfig": "tsconfig.spec.json",
190192
"karmaConfig": "karma.conf.js",
191193
"ngxEnv": {

examples/apps/ng-app-cli/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"@angular/animations": "^17.2.0",
2222
"@angular/common": "^17.2.0",
23+
"@angular/localize": "^17.2.0",
2324
"@angular/compiler": "^17.2.0",
2425
"@angular/core": "^17.2.0",
2526
"@angular/forms": "^17.2.0",
@@ -37,24 +38,23 @@
3738
"@angular-devkit/build-angular": "^17.2.0",
3839
"@angular/cli": "^17.2.0",
3940
"@angular/compiler-cli": "^17.2.0",
40-
"@angular/localize": "^17.2.0",
41-
"@ngx-env/builder": "file:../../../packages/angular",
41+
"@dotenv-run/core": "*",
42+
"@dotenv-run/jest-angular": "*",
43+
"@jest/transform": "^29.7.0",
44+
"@ngx-env/builder": "*",
4245
"@types/express": "^4.17.17",
4346
"@types/jasmine": "~5.1.0",
4447
"@types/node": "^18.18.0",
48+
"esbuild": "0.20.0",
4549
"jasmine-core": "~5.1.0",
50+
"jest": "^29.7.0",
51+
"jest-preset-angular": "14.0.0",
4652
"karma": "~6.4.0",
4753
"karma-chrome-launcher": "~3.2.0",
4854
"karma-coverage": "~2.2.0",
4955
"karma-jasmine": "~5.1.0",
5056
"karma-jasmine-html-reporter": "~2.1.0",
51-
"typescript": "~5.2.2",
5257
"ts-jest": "^29.1.2",
53-
"@jest/transform": "^29.7.0",
54-
"esbuild": "0.20.0",
55-
"jest": "^29.7.0",
56-
"jest-preset-angular": "14.0.0",
57-
"@dotenv-run/core": "*",
58-
"@dotenv-run/jest-angular": "*"
58+
"typescript": "~5.2.2"
5959
}
6060
}

examples/apps/ng-app-cli/server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export function app(): express.Express {
2020
// Example Express Rest API endpoints
2121
// server.get('/api/**', (req, res) => { });
2222
// Serve static files from /browser
23-
server.get('*.*', express.static(browserDistFolder, {
24-
maxAge: '1y'
25-
}));
23+
server.get(
24+
'*.*',
25+
express.static(browserDistFolder, {
26+
maxAge: '1y',
27+
})
28+
);
2629

2730
// All regular routes use the Angular engine
2831
server.get('*', (req, res, next) => {

examples/apps/ng-app-cli/src/app/app.config.server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { provideServerRendering } from '@angular/platform-server';
33
import { appConfig } from './app.config';
44

55
const serverConfig: ApplicationConfig = {
6-
providers: [
7-
provideServerRendering()
8-
]
6+
providers: [provideServerRendering()],
97
};
108

119
export const config = mergeApplicationConfig(appConfig, serverConfig);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
1+
import { ApplicationConfig } from '@angular/core';
22
import { provideRouter } from '@angular/router';
33

4-
import { routes } from './app.routes';
54
import { provideClientHydration } from '@angular/platform-browser';
5+
import { routes } from './app.routes';
66

77
export const appConfig: ApplicationConfig = {
8-
providers: [provideRouter(routes), provideClientHydration()]
8+
providers: [provideRouter(routes), provideClientHydration()],
99
};

examples/apps/ng-app-cli/src/env.d.ts

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,13 @@
1-
interface ImportMeta {
2-
readonly env: ImportMetaEnv;
3-
}
4-
5-
interface ImportMetaEnv {
6-
/**
7-
* Built-in environment variable.
8-
* @see Docs https://github.com/chihab/dotenv-run/packages/angular#node_env.
9-
*/
1+
// Define the type of the environment variables.
2+
declare interface Env {
103
readonly NODE_ENV: string;
11-
// Add your environment variables below
12-
// readonly NG_APP_API_URL: string;
4+
// Replace the following with your own environment variables.
5+
// Example: NGX_VERSION: string;
6+
NGX_BRANCH: string;
7+
NGX_VERSION: string;
138
[key: string]: any;
149
}
1510

16-
/*
17-
* Remove all the deprecated code below if you're using import.meta.env (recommended)
18-
*/
19-
20-
/****************************** DEPREACTED **************************/
21-
/**
22-
* @deprecated process.env usage
23-
* prefer using import.meta.env
24-
* */
25-
// declare var process: {
26-
// env: {
27-
// NODE_ENV: string;
28-
// [key: string]: any;
29-
// };
30-
// };
31-
32-
// If your project references @types/node directly (in you) or indirectly (as in RxJS < 7.6.0),
33-
// you might need to use the following declaration merging.
34-
// declare namespace NodeJS {
35-
// export interface ProcessEnv {
36-
// readonly NODE_ENV: string;
37-
// // Add your environment variables below
38-
// }
39-
// }
40-
41-
// If you're using Angular Universal and process.env notation, you'll need to add the following to your tsconfig.server.json:
42-
/* In your tsconfig.server.json */
43-
// {
44-
// "extends": "./tsconfig.app.json",
45-
// ...
46-
// "exclude": [
47-
// "src/env.d.ts"
48-
// ]
49-
// }
50-
51-
/*********************************************************************/
11+
declare interface ImportMeta {
12+
readonly env: Env;
13+
}

examples/apps/ng-app-cli/src/locale/messages.fr.xlf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
<body>
55
<trans-unit id="156685006078229661" datatype="html">
66
<source>Attribute string</source>
7-
<target>Attribute string</target>
87
<context-group purpose="location">
98
<context context-type="sourcefile">src/app/app.component.html</context>
109
<context context-type="linenumber">3</context>
1110
</context-group>
1211
</trans-unit>
1312
<trans-unit id="398840060331148207" datatype="html">
1413
<source>element string</source>
15-
<target>element string</target>
1614
<context-group purpose="location">
1715
<context context-type="sourcefile">src/app/app.component.html</context>
1816
<context context-type="linenumber">3,4</context>
1917
</context-group>
2018
</trans-unit>
2119
<trans-unit id="2023484548631819319" datatype="html">
2220
<source>Hello world</source>
23-
<target>Hello world</target>
2421
<context-group purpose="location">
2522
<context context-type="sourcefile">src/app/app.component.ts</context>
2623
<context context-type="linenumber">14</context>

examples/apps/ng-app-cli/src/main.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '@ngx-env/builder/runtime';
2+
13
import { bootstrapApplication } from '@angular/platform-browser';
24
import { AppComponent } from './app/app.component';
35
import { config } from './app/app.config.server';

examples/apps/ng-app-cli/src/polyfills.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/apps/ng-app-cli/tsconfig.app.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
"outDir": "./out-tsc/app",
66
"types": ["node", "@angular/localize"]
77
},
8-
"files": [
9-
"src/main.ts",
10-
"src/polyfills.ts",
11-
"src/main.server.ts",
12-
"server.ts"
13-
],
8+
"files": ["src/main.ts", "src/main.server.ts", "server.ts"],
149
"include": ["src/**/*.d.ts"]
1510
}

examples/apps/ng-app-cli/tsconfig.spec.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,5 @@
66
"esModuleInterop": true,
77
"module": "es2022"
88
},
9-
"include": [
10-
"src/**/*.spec.ts",
11-
"src/**/*.jest.ts",
12-
"src/polyfills.ts",
13-
"src/**/*.d.ts"
14-
]
9+
"include": ["src/**/*.spec.ts", "src/**/*.jest.ts", "src/**/*.d.ts"]
1510
}

examples/apps/ng-app-webpack/angular.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@
2525
"main": "src/main.ts",
2626
"polyfills": "src/polyfills.ts",
2727
"tsConfig": "tsconfig.app.json",
28-
"assets": [
29-
"src/favicon.ico",
30-
"src/assets"
31-
],
32-
"styles": [
33-
"src/styles.css"
34-
],
28+
"assets": ["src/favicon.ico", "src/assets"],
29+
"styles": ["src/styles.css"],
3530
"scripts": []
3631
},
3732
"configurations": {
@@ -82,4 +77,4 @@
8277
}
8378
}
8479
}
85-
}
80+
}

examples/apps/ng-app-webpack/tsconfig.app.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
"outDir": "./out-tsc/app",
66
"types": []
77
},
8-
"files": [
9-
"src/main.ts",
10-
"src/polyfills.ts"
11-
],
12-
"include": [
13-
"src/**/*.d.ts"
14-
]
8+
"files": ["src/main.ts", "src/polyfills.ts"],
9+
"include": ["src/**/*.d.ts"]
1510
}

examples/apps/ng-app-webpack/tsconfig.spec.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
"extends": "./tsconfig.json",
44
"compilerOptions": {
55
"outDir": "./out-tsc/spec",
6-
"types": [
7-
"jasmine"
8-
]
6+
"types": ["jasmine"]
97
},
10-
"files": [
11-
"src/test.ts",
12-
"src/polyfills.ts"
13-
],
14-
"include": [
15-
"src/**/*.spec.ts",
16-
"src/**/*.d.ts"
17-
]
8+
"files": ["src/test.ts"],
9+
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
1810
}

examples/package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
"devDependencies": {
1111
"@dotenv-run/cli": "^1.3.5",
1212
"@dotenv-run/load": "^1.3.4",
13-
"@dotenv-run/webpack": "^1.3.4",
1413
"@dotenv-run/rollup": "^1.3.4",
15-
"webpack": "5.90.1",
16-
"serve": "^14.2.1",
14+
"@dotenv-run/webpack": "^1.3.4",
15+
"@nx/js": "^18.2.1",
1716
"@playwright/test": "^1.37.1",
18-
"webpack-cli": "^5.0.0",
17+
"nx": "^16.5.5",
1918
"rollup": "^3.0.0",
20-
"nx": "^16.5.5"
21-
}
19+
"serve": "^14.2.1",
20+
"verdaccio": "^5.0.4",
21+
"webpack": "5.90.1",
22+
"webpack-cli": "^5.0.0"
23+
},
24+
"nx": {
25+
"includedScripts": []
26+
},
27+
"dependencies": {}
2228
}

examples/project.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "platform",
3+
"$schema": "node_modules/nx/schemas/project-schema.json",
4+
"targets": {
5+
"local-registry": {
6+
"executor": "@nx/js:verdaccio",
7+
"options": {
8+
"port": 4873,
9+
"config": ".verdaccio/config.yml",
10+
"storage": "tmp/local-registry/storage"
11+
}
12+
}
13+
}
14+
}

packages/angular/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-env/builder",
3-
"version": "17.2.3",
3+
"version": "17.3.0-alpha.0",
44
"description": "Easily inject environment variables into your Angular applications",
55
"author": "chihab <chihab@gmail.com>",
66
"homepage": "https://github.com/chihab/ngx-env/tree/main/packages/angular",
@@ -16,7 +16,8 @@
1616
"dist",
1717
"builders.json",
1818
"collection.json",
19-
"README.md"
19+
"README.md",
20+
"runtime.mjs"
2021
],
2122
"builders": "builders.json",
2223
"schematics": "./collection.json",
@@ -29,7 +30,7 @@
2930
"copy-dist": "ts-node tools/schema-dist.ts"
3031
},
3132
"dependencies": {
32-
"@dotenv-run/esbuild": "^1.3.4",
33+
"@dotenv-run/esbuild": "^1.3.5",
3334
"@dotenv-run/webpack": "^1.3.4",
3435
"glob": "^10.3.10"
3536
},

0 commit comments

Comments
 (0)