You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

angular-server-side-configuration

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-server-side-configuration - npm Package Compare versions

Comparing version

to
11.0.1

scripts/standard-version-updater.js

2

builders/builders.json

@@ -9,2 +9,2 @@ {

}
}
}

@@ -31,8 +31,10 @@ 'use strict';

const variantImport = this._findNodesOfType(node, typescript.SyntaxKind.ImportDeclaration)
.map(n => n.getFullText().trim())
.filter(n => n.includes('angular-server-side-configuration'))[0];
.map((n) => n.getFullText().trim())
.filter((n) => n.includes('angular-server-side-configuration'))[0];
if (!variantImport || variantImport.match(/angular-server-side-configuration\/process/)) {
return { variant: 'process', variantImport };
}
const variant = variantImport.match(/angular-server-side-configuration\/ng-env/) ? 'NG_ENV' : undefined;
const variant = variantImport.match(/angular-server-side-configuration\/ng-env/)
? 'NG_ENV'
: undefined;
if (!variant) {

@@ -46,3 +48,3 @@ throw new Error('Could not detect variant (expected either process or ng-env)');

.sort((a, b) => b.parent.parent.getText().length - a.parent.parent.getText().length)
.map(n => ({
.map((n) => ({
expression: this._resolveExpression(n.parent),

@@ -54,5 +56,5 @@ variable: n.parent.parent.getText().split('.')[2],

return this._findUsages(node, 'NG_ENV')
.filter(n => n.kind === typescript.SyntaxKind.Identifier && n.parent.kind !== typescript.SyntaxKind.ImportSpecifier)
.filter((n) => n.kind === typescript.SyntaxKind.Identifier && n.parent.kind !== typescript.SyntaxKind.ImportSpecifier)
.sort((a, b) => b.parent.getText().length - a.parent.getText().length)
.map(n => ({
.map((n) => ({
expression: this._resolveExpression(n),

@@ -65,3 +67,3 @@ variable: n.parent.getText().split('.')[1],

.getChildren()
.map(c => this._findNodesOfType(c, kind))
.map((c) => this._findNodesOfType(c, kind))
.reduce((current, next) => current.concat(...next), node.kind === kind ? [node] : []);

@@ -72,3 +74,3 @@ }

.getChildren()
.map(c => this._findUsages(c, variant))
.map((c) => this._findUsages(c, variant))
.reduce((current, next) => current.concat(next), node.getText() === variant ? [node] : []);

@@ -96,3 +98,3 @@ }

untokenize(fileContent) {
if (!this._variables.some(v => fileContent.includes(v.token))) {
if (!this._variables.some((v) => fileContent.includes(v.token))) {
return fileContent;

@@ -117,6 +119,4 @@ }

tokenize(sourceContent, ngsscContext) {
const tokenizedVariables = ngsscContext.variables
.map(v => ({ ...v, token: `ngssc-token-${++this._tokenCounter}-${Date.now()}` }));
const tokenizedFileContent = tokenizedVariables
.reduce((current, next) => current.replace(next.expression, `"${next.token}" as any`), this._adaptImport(sourceContent, ngsscContext));
const tokenizedVariables = ngsscContext.variables.map((v) => (Object.assign(Object.assign({}, v), { token: `ngssc-token-${++this._tokenCounter}-${Date.now()}` })));
const tokenizedFileContent = tokenizedVariables.reduce((current, next) => current.replace(next.expression, `"${next.token}" as any`), this._adaptImport(sourceContent, ngsscContext));
return new TokenizeResult(tokenizedFileContent, tokenizedVariables);

@@ -172,3 +172,3 @@ }

this._context.logger.info(`ngssc: Detected variant '${ngsscContext.variant}' with variables ` +
`'${ngsscContext.variables.map(v => v.variable).join(', ')}'`);
`'${ngsscContext.variables.map((v) => v.variable).join(', ')}'`);
return ngsscContext;

@@ -185,9 +185,9 @@ }

await writeFileAsync(tmpNgsscEnvironmentFilePath, this._tokenizeResult.content, 'utf8');
return { ...rawBrowserOptions, fileReplacements: this._buildFileReplacements(rawBrowserOptions) };
return Object.assign(Object.assign({}, rawBrowserOptions), { fileReplacements: this._buildFileReplacements(rawBrowserOptions) });
}
_buildFileReplacements(rawBrowserOptions) {
const fileReplacements = (rawBrowserOptions.fileReplacements || [])
.map(f => 'with' in f ? { ...f } : { replace: f.src, with: f.replaceWith })
.filter(f => f.with === this._options.ngsscEnvironmentFile)
.map(f => ({ replace: f.replace, with: this._tmpNgsscEnvironmentFile }));
.map((f) => ('with' in f ? Object.assign({}, f) : { replace: f.src, with: f.replaceWith }))
.filter((f) => f.with === this._options.ngsscEnvironmentFile)
.map((f) => ({ replace: f.replace, with: this._tmpNgsscEnvironmentFile }));
if (!fileReplacements.length) {

@@ -204,3 +204,3 @@ throw new Error(`Expected a fileReplacements entry in the referenced browserTarget '${this._options.browserTarget}'` +

environmentVariables: [
...ngsscContext.variables.map(m => m.variable),
...ngsscContext.variables.map((m) => m.variable),
...(this._options.additionalEnvironmentVariables || []),

@@ -219,5 +219,3 @@ ],

const files = await readdirAsync(outputPath);
for (const file of files
.filter(f => f.endsWith('.js'))
.map(f => path.join(outputPath, f))) {
for (const file of files.filter((f) => f.endsWith('.js')).map((f) => path.join(outputPath, f))) {
const fileContent = await readFileAsync(file, 'utf8');

@@ -224,0 +222,0 @@ const newFileContent = this._tokenizeResult.untokenize(fileContent);

@@ -29,2 +29,2 @@ {

}
}
}

@@ -5,50 +5,47 @@ # Changelog

### [11.0.1](https://github.com/kyubisation/angular-server-side-configuration/compare/v11.0.0...v11.0.1) (2020-11-16)
## [11.0.0](https://github.com/kyubisation/angular-server-side-configuration/compare/v10.2.0...v11.0.0) (2020-11-16)
## [10.2.0](https://github.com/kyubisation/angular-server-side-configuration/compare/v10.1.0...v10.2.0) (2020-10-25)
### Features
* update download url of Dockerfiles if available ([368e5eb](https://github.com/kyubisation/angular-server-side-configuration/commit/368e5eba3a6f23ef13ca47ad32c0cc30be8e54f4))
- update download url of Dockerfiles if available ([368e5eb](https://github.com/kyubisation/angular-server-side-configuration/commit/368e5eba3a6f23ef13ca47ad32c0cc30be8e54f4))
## [10.1.0](https://github.com/kyubisation/angular-server-side-configuration/compare/v10.0.1...v10.1.0) (2020-10-18)
### Features
* add ngsw.json detection and updating to native cli ([1dd77fa](https://github.com/kyubisation/angular-server-side-configuration/commit/1dd77fa943793b6aaa83f34efa87dbc2ef4c4015))
- add ngsw.json detection and updating to native cli ([1dd77fa](https://github.com/kyubisation/angular-server-side-configuration/commit/1dd77fa943793b6aaa83f34efa87dbc2ef4c4015))
### [10.0.1](https://github.com/kyubisation/angular-server-side-configuration/compare/v10.0.0...v10.0.1) (2020-07-05)
### Bug Fixes
* correct linting ([3ac1181](https://github.com/kyubisation/angular-server-side-configuration/commit/3ac1181c74227b7d99a295f66b5f44995eab26f4))
- correct linting ([3ac1181](https://github.com/kyubisation/angular-server-side-configuration/commit/3ac1181c74227b7d99a295f66b5f44995eab26f4))
## [10.0.0](https://github.com/kyubisation/angular-server-side-configuration/compare/v9.0.2...v10.0.0) (2020-07-05)
### ⚠ BREAKING CHANGES
* Updating to Angular 10.
- Updating to Angular 10.
### Features
* add ngssc binaries for OSX (darwin) ([0561921](https://github.com/kyubisation/angular-server-side-configuration/commit/05619218bf7c748ebfefa94b27d74c9c5fe89a23))
- add ngssc binaries for OSX (darwin) ([0561921](https://github.com/kyubisation/angular-server-side-configuration/commit/05619218bf7c748ebfefa94b27d74c9c5fe89a23))
- update to Angular 10 ([2b3e6b7](https://github.com/kyubisation/angular-server-side-configuration/commit/2b3e6b7f49ab4988deac1d8765ab7e394e967e82))
* update to Angular 10 ([2b3e6b7](https://github.com/kyubisation/angular-server-side-configuration/commit/2b3e6b7f49ab4988deac1d8765ab7e394e967e82))
### [9.0.2](https://github.com/kyubisation/angular-server-side-configuration/compare/v9.0.1...v9.0.2) (2020-03-03)
### Bug Fixes
* export schematics factories named ([8c44ff3](https://github.com/kyubisation/angular-server-side-configuration/commit/8c44ff3aadce1764a28a2c53e00d895c81a24fc8))
- export schematics factories named ([8c44ff3](https://github.com/kyubisation/angular-server-side-configuration/commit/8c44ff3aadce1764a28a2c53e00d895c81a24fc8))
### [9.0.1](https://github.com/kyubisation/angular-server-side-configuration/compare/v9.0.0...v9.0.1) (2020-03-02)
### Bug Fixes
* export ngsscBuild as a function and builder as default ([dc2ae70](https://github.com/kyubisation/angular-server-side-configuration/commit/dc2ae70397697701ced82fb5aaba467adb0b2c93))
- export ngsscBuild as a function and builder as default ([dc2ae70](https://github.com/kyubisation/angular-server-side-configuration/commit/dc2ae70397697701ced82fb5aaba467adb0b2c93))

@@ -59,35 +56,30 @@ ## [9.0.0](https://github.com/kyubisation/angular-server-side-configuration/compare/v9.0.0-next.0...v9.0.0) (2020-02-07)

### Features
* make insert commands idempotent ([3c55e34](https://github.com/kyubisation/angular-server-side-configuration/commit/3c55e34eb210033b976c4a8208023d8ef98580f6))
* upgrade to angular 9-rc ([f948ae5](https://github.com/kyubisation/angular-server-side-configuration/commit/f948ae5d5e5085bda112ffa77f9ee5f43713628d))
- make insert commands idempotent ([3c55e34](https://github.com/kyubisation/angular-server-side-configuration/commit/3c55e34eb210033b976c4a8208023d8ef98580f6))
- upgrade to angular 9-rc ([f948ae5](https://github.com/kyubisation/angular-server-side-configuration/commit/f948ae5d5e5085bda112ffa77f9ee5f43713628d))
### [8.2.1](https://github.com/kyubisation/angular-server-side-configuration/compare/v8.2.0...v8.2.1) (2020-01-23)
### Bug Fixes
* mark new filePattern option as optional ([b43ca20](https://github.com/kyubisation/angular-server-side-configuration/commit/b43ca20ed3db86336e3322fc78085fb70e1723ef))
- mark new filePattern option as optional ([b43ca20](https://github.com/kyubisation/angular-server-side-configuration/commit/b43ca20ed3db86336e3322fc78085fb70e1723ef))
## [8.2.0](https://github.com/kyubisation/angular-server-side-configuration/compare/v8.1.3...v8.2.0) (2020-01-23)
### Features
* add filePattern option to builder ([e7d51be](https://github.com/kyubisation/angular-server-side-configuration/commit/e7d51be81926dd1d0d9199d06b077b219831b396)), closes [#37](https://github.com/kyubisation/angular-server-side-configuration/issues/37)
- add filePattern option to builder ([e7d51be](https://github.com/kyubisation/angular-server-side-configuration/commit/e7d51be81926dd1d0d9199d06b077b219831b396)), closes [#37](https://github.com/kyubisation/angular-server-side-configuration/issues/37)
### [8.1.3](https://github.com/kyubisation/angular-server-side-configuration/compare/v8.1.2...v8.1.3) (2020-01-20)
### Bug Fixes
* tokenizer should not short circuit ([d849f6c](https://github.com/kyubisation/angular-server-side-configuration/commit/d849f6cb5b9575fbf85e7daae084957f8b4433e5)), closes [#38](https://github.com/kyubisation/angular-server-side-configuration/issues/38)
- tokenizer should not short circuit ([d849f6c](https://github.com/kyubisation/angular-server-side-configuration/commit/d849f6cb5b9575fbf85e7daae084957f8b4433e5)), closes [#38](https://github.com/kyubisation/angular-server-side-configuration/issues/38)
### [8.1.2](https://github.com/kyubisation/angular-server-side-configuration/compare/v8.1.1...v8.1.2) (2020-01-12)
### Bug Fixes
* bump handlebars from 4.1.2 to 4.5.3 ([#35](https://github.com/kyubisation/angular-server-side-configuration/issues/35)) ([de53338](https://github.com/kyubisation/angular-server-side-configuration/commit/de533381723afd94f18f1a9decf3e93c6d566600))
- bump handlebars from 4.1.2 to 4.5.3 ([#35](https://github.com/kyubisation/angular-server-side-configuration/issues/35)) ([de53338](https://github.com/kyubisation/angular-server-side-configuration/commit/de533381723afd94f18f1a9decf3e93c6d566600))

@@ -98,3 +90,3 @@ ### [8.1.1](https://github.com/kyubisation/angular-server-side-configuration/compare/8.1.0...8.1.1) (2019-10-23)

* No longer changing working directory in the cli
- No longer changing working directory in the cli

@@ -105,3 +97,3 @@ ### [8.1.0](https://github.com/kyubisation/angular-server-side-configuration/compare/8.0.0...8.1.0) (2019-10-23)

* Add uncompressed binaries
- Add uncompressed binaries

@@ -112,3 +104,3 @@ ### [8.0.0](https://github.com/kyubisation/angular-server-side-configuration/compare/8.0.0-beta.4...8.0.0) (2019-08-25)

* Fixed issue with native cli --recursive
- Fixed issue with native cli --recursive

@@ -119,3 +111,3 @@ ### [8.0.0-beta.4](https://github.com/kyubisation/angular-server-side-configuration/compare/8.0.0-beta.3...8.0.0-beta.4) (2019-07-19)

* Fixed iife insertion
- Fixed iife insertion

@@ -126,3 +118,3 @@ ### [8.0.0-beta.3](https://github.com/kyubisation/angular-server-side-configuration/compare/8.0.0-beta.2...8.0.0-beta.3) (2019-07-19)

* Fixed dependency issue with glob-to-regexp
- Fixed dependency issue with glob-to-regexp

@@ -133,7 +125,7 @@ ### [8.0.0-beta.2](https://github.com/kyubisation/angular-server-side-configuration/compare/8.0.0-beta.1...8.0.0-beta.2) (2019-07-19)

* Implemented insert function (`import { insert } from 'angular-server-side-configuration';`)
- Implemented insert function (`import { insert } from 'angular-server-side-configuration';`)
### Bugfix
* Fixed issue in native cli
- Fixed issue in native cli

@@ -144,4 +136,4 @@ ### [8.0.0-beta.1](https://github.com/kyubisation/angular-server-side-configuration/compare/8.0.0-beta.0...8.0.0-beta.1) (2019-07-14)

* Added additionalEnvironmentVariables to builder options
* Implemented ng update migration
- Added additionalEnvironmentVariables to builder options
- Implemented ng update migration

@@ -152,9 +144,9 @@ ### [8.0.0-beta.0](https://github.com/kyubisation/angular-server-side-configuration/compare/2.0.0...8.0.0-beta.0) (2019-06-30)

* Rewrote the library to use Angular schematics and builders
* Added --recursive flag to the native CLI
- Rewrote the library to use Angular schematics and builders
- Added --recursive flag to the native CLI
### Breaking Changes
* Removed the npm CLI and most of the existing internal implementation
* Dropped support for configuration embedded in html
- Removed the npm CLI and most of the existing internal implementation
- Dropped support for configuration embedded in html

@@ -165,3 +157,3 @@ ### [2.0.0](https://github.com/kyubisation/angular-server-side-configuration/compare/2.0.0-beta.1...2.0.0) (2019-04-14)

* Added documentation for the native cli
- Added documentation for the native cli

@@ -177,8 +169,8 @@ ### [2.0.0-beta.1](https://github.com/kyubisation/angular-server-side-configuration/compare/2.0.0-beta.0...2.0.0-beta.1) (2019-04-13)

* New command `ngssc` for detecting environment variable usage
- New command `ngssc` for detecting environment variable usage
### Breaking Changes
* The `ngssc wrap-aot` has been merged into the `ngssc` command as an optional flag `--wrap-aot`.
* The `ngssc insert` command requires an ngssc.json file or embedded configuration in the html files.
- The `ngssc wrap-aot` has been merged into the `ngssc` command as an optional flag `--wrap-aot`.
- The `ngssc insert` command requires an ngssc.json file or embedded configuration in the html files.

@@ -189,7 +181,7 @@ ### [2.0.0-beta.0](https://github.com/kyubisation/angular-server-side-configuration/compare/1.3.0...2.0.0-beta.0) (2019-03-10)

* Implemented NG_ENV variant as an alternative for process.env
- Implemented NG_ENV variant as an alternative for process.env
### Breaking Changes
* Removed deprecated ProcessEnvConfiguration
- Removed deprecated ProcessEnvConfiguration

@@ -200,11 +192,11 @@ ### [1.3.0](https://github.com/kyubisation/angular-server-side-configuration/compare/1.2.1...1.3.0) (2019-03-09)

* Created ProcessEnvConfiguration, which will replace EnvironmentVariablesConfiguration
* Created class Configuration, which is the base implementation for ProcessEnvConfiguration and EnvironmentVariablesConfiguration
- Created ProcessEnvConfiguration, which will replace EnvironmentVariablesConfiguration
- Created class Configuration, which is the base implementation for ProcessEnvConfiguration and EnvironmentVariablesConfiguration
### Deprecation
* EnvironmentVariablesConfiguration has been deprecated. Use ProcessEnvConfiguration instead
- EnvironmentVariablesConfiguration has been deprecated. Use ProcessEnvConfiguration instead
### Internal Changes
* Switched testing framework from mocha/chai/nyc to jest
- Switched testing framework from mocha/chai/nyc to jest
export declare var NG_ENV: {
[name: string]: string;
[name: string]: string;
};
var globalVariable = {};
try {
globalVariable = window;
}
catch (e) { }
globalVariable = window;
} catch (e) {}
export var NG_ENV = globalVariable.NG_ENV || {};

@@ -7,6 +7,3 @@ {

"title": "The Ngssc Schema",
"required": [
"variant",
"environmentVariables"
],
"required": ["variant", "environmentVariables"],
"properties": {

@@ -18,5 +15,3 @@ "variant": {

"default": "",
"examples": [
"process"
],
"examples": ["process"],
"pattern": "^(process|NG_ENV)$"

@@ -33,5 +28,3 @@ },

"default": "",
"examples": [
"TEST_VALUE"
],
"examples": ["TEST_VALUE"],
"pattern": "^([\\w_]*)$"

@@ -45,8 +38,6 @@ }

"default": "",
"examples": [
"**/index.html"
],
"examples": ["**/index.html"],
"pattern": "^(.*)$"
}
}
}
}
{
"name": "angular-server-side-configuration",
"version": "10.2.0",
"version": "11.0.1",
"description": "Configure an angular application on the server",

@@ -15,2 +15,3 @@ "builders": "./builders/builders.json",

"build": "run-p build:*",
"format": "prettier --write **/*.{js,ts,css,scss,json,md,html}",
"pretest": "npm run clean",

@@ -21,4 +22,3 @@ "test:node": "jest --ci",

"lint": "tslint -p tsconfig.json",
"release": "standard-version",
"prepack": "node scripts/patch-dockerfile-migration-version.js"
"release": "standard-version"
},

@@ -54,8 +54,8 @@ "main": "./src/main.js",

"devDependencies": {
"@angular-devkit/architect": "~0.1000.0",
"@angular-devkit/core": "^10.0.0",
"@angular-devkit/schematics": "^10.0.0",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@schematics/angular": "^10.0.0",
"@angular-devkit/architect": "~0.1100.0",
"@angular-devkit/core": "^11.0.0",
"@angular-devkit/schematics": "^11.0.0",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@schematics/angular": "^11.0.0",
"@types/glob-to-regexp": "^0.4.0",

@@ -65,15 +65,43 @@ "@types/jest": "^26.0.15",

"@types/rimraf": "^3.0.0",
"@wessberg/rollup-plugin-ts": "^1.3.6",
"@wessberg/rollup-plugin-ts": "^1.3.8",
"glob-to-regexp": "^0.4.1",
"jest": "^26.6.1",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"rimraf": "^3.0.2",
"rollup": "^2.32.1",
"rollup": "^2.33.1",
"standard-version": "^9.0.0",
"ts-jest": "^26.4.2",
"ts-jest": "^26.4.4",
"ts-node": "^9.0.0",
"tslint": "^6.1.3",
"typescript": "~3.9.6"
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"typescript": "~4.0.5"
},
"prettier": {
"singleQuote": true,
"endOfLine": "lf",
"printWidth": 100
},
"standard-version": {
"bumpFiles": [
{
"filename": "package.json",
"type": "json"
},
{
"filename": "package-lock.json",
"type": "json"
},
{
"filename": "schematics/migration.json",
"updater": "scripts/standard-version-updater.js"
},
{
"filename": "README.md",
"updater": "scripts/standard-version-updater.js"
}
]
},
"jest": {

@@ -80,0 +108,0 @@ "preset": "ts-jest",

declare namespace NodeJS {
interface NodeProcess {
env?: any;
env?: any;
}

@@ -5,0 +5,0 @@ interface Process extends NodeProcess {}

@@ -1,2 +0,2 @@

(function(self) {
(function (self) {
if (self) {

@@ -6,2 +6,2 @@ self.process = self.process || {};

}
})(typeof window === 'object' ? window : undefined);
})(typeof window === 'object' ? window : undefined);

@@ -8,6 +8,6 @@ # angular-server-side-configuration

Configure an angular application at runtime on the server or in a docker container via environment variables.
## Motivation
The Angular CLI provides build time configuration (via environment.ts).

@@ -17,2 +17,3 @@ In a Continuous Delivery environment this is sometimes not enough.

## How it works
Environment variables are used for configuration.

@@ -26,2 +27,3 @@ This package provides an Angular CLI builder to search for usages at build time.

## Version 8/9 Changes
Version 8.x of this package was a complete rewrite with Angular schematics and builders.

@@ -37,12 +39,17 @@ If you require support for older Angular versions,

## Getting Started
```
ng add angular-server-side-configuration
```
or, if you have a previous version of this library installed
```
ng update angular-server-side-configuration@latest
```
This will configure the appropriate files.
Alternatively, if you want to configure the files yourself:
```

@@ -53,2 +60,3 @@ npm install --save angular-server-side-configuration

### angular.json
Ensure you have an `ngsscbuild` entry in your project `architect` section.

@@ -77,3 +85,3 @@ To use the builder run `ng run your-project-name:ngsscbuild:production`.

"ngsscEnvironmentFile": "src/environments/environment.prod.ts",
// Optional
// Optional
// (Defaults to the basename of the index option of the browser target)

@@ -100,6 +108,8 @@ "filePattern": "index.html"

### environment.prod.ts
angular-server-side-configuration supports two variants for using environment variables:
process.env.* or NG_ENV.*
process.env._ or NG_ENV._
#### process.env.*
#### process.env.\*
Use process.env.NAME in your environment.prod.ts, where NAME is the

@@ -113,8 +123,9 @@ environment variable that should be used.

production: process.env.PROD !== 'false',
apiAddress: process.env.API_ADDRESS || 'https://example-api.com'
apiAddress: process.env.API_ADDRESS || 'https://example-api.com',
};
```
#### NG_ENV.*
Import NG_ENV from `angular-server-side-configuration/ng-env`
#### NG_ENV.\*
Import NG_ENV from `angular-server-side-configuration/ng-env`
and use NG_ENV.NAME in your environment.prod.ts, where NAME is the

@@ -128,3 +139,3 @@ environment variable that should be used.

production: NG_ENV.PROD !== 'false',
apiAddress: NG_ENV.API_ADDRESS || 'https://example-api.com'
apiAddress: NG_ENV.API_ADDRESS || 'https://example-api.com',
};

@@ -134,2 +145,3 @@ ```

### index.html (Optional)
Add `<!--CONFIG-->` to index.html. This will be replaced by the configuration script tag.

@@ -140,16 +152,16 @@ This is optional, as the environment variables can be configured to be inserted in the head tag.

```html
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular Example</title>
<!--CONFIG-->
<base href="/">
<head>
<meta charset="utf-8" />
<title>Angular Example</title>
<!--CONFIG-->
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>

@@ -159,2 +171,3 @@ ```

### On host server or in Dockerfile
This library provides a Node.js and a native implementation for inserting the environment variables into your html.

@@ -172,14 +185,17 @@ Either the `insert` function from the package (`import { insert } from 'angular-server-side-configuration';`)

#### ngssc insert
Usage: ngssc insert [options] [directory]
| Options | Description |
| --- | --- |
| Options | Description |
| ----------------- | --------------------------------------------------------------------------------- |
| `-r, --recursive` | Recursively searches for ngssc.json files and applies the contained configuration |
| `--dry` | Perform the insert without actually inserting the variables |
| `--dry` | Perform the insert without actually inserting the variables |
##### Minimal Example
Dockerfile
```Dockerfile
FROM nginx:alpine
ADD https://github.com/kyubisation/angular-server-side-configuration/releases/download/v10.2.0/ngssc_64bit /usr/sbin/ngssc
ADD https://github.com/kyubisation/angular-server-side-configuration/releases/download/v11.0.1/ngssc_64bit /usr/sbin/ngssc
RUN chmod +x /usr/sbin/ngssc

@@ -193,2 +209,3 @@ COPY dist /usr/share/nginx/html

start.sh
```bash

@@ -213,2 +230,3 @@ #!/bin/sh

## License
Apache License, Version 2.0
Apache License, Version 2.0
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import ts from "@wessberg/rollup-plugin-ts";
import ts from '@wessberg/rollup-plugin-ts';
import { join } from 'path';
export default ['./builders/ngsscbuild', './schematics/ng-add', './schematics/ng-update'].map(p => ({
input: join(p, 'index.ts'),
output: {
file: join(p, 'index.js'),
format: 'cjs',
exports: 'named'
},
external: [
'@angular-devkit/architect',
'@angular-devkit/core',
'@angular-devkit/schematics',
'@schematics/angular/utility/change',
'@schematics/angular/utility/config',
'crypto',
'fs',
'path',
'util',
'typescript'
],
plugins: [
ts({ browserslist: false })
]
})).concat({
input: './src/index.ts',
output: [
{
file: './src/main.js',
export default ['./builders/ngsscbuild', './schematics/ng-add', './schematics/ng-update']
.map((p) => ({
input: join(p, 'index.ts'),
output: {
file: join(p, 'index.js'),
format: 'cjs',
exports: 'named',
},
{
file: './src/module.js',
format: 'esm',
}
],
external: [
'fs',
'path'
],
plugins: [
ts({ browserslist: false }),
resolve(),
commonjs()
]
});
external: [
'@angular-devkit/architect',
'@angular-devkit/core',
'@angular-devkit/schematics',
'@schematics/angular/utility/change',
'@schematics/angular/utility/workspace',
'crypto',
'fs',
'path',
'util',
'typescript',
],
plugins: [ts({ browserslist: false })],
}))
.concat({
input: './src/index.ts',
output: [
{
file: './src/main.js',
format: 'cjs',
},
{
file: './src/module.js',
format: 'esm',
},
],
external: ['fs', 'path'],
plugins: [ts({ browserslist: false }), resolve(), commonjs()],
});

@@ -11,2 +11,2 @@ {

}
}
}

@@ -15,3 +15,3 @@ {

"dockerfile": {
"version": "10.2.0",
"version": "11.0.1",
"description": "Updates the download url for ngssc",

@@ -18,0 +18,0 @@ "factory": "./ng-update/index#dockerfile"

@@ -8,3 +8,3 @@ 'use strict';

var change = require('@schematics/angular/utility/change');
var config = require('@schematics/angular/utility/config');
var workspace = require('@schematics/angular/utility/workspace');

@@ -20,30 +20,34 @@ function ngAdd(options) {

function addNgsscTargetToWorkspace(options) {
return (host, context) => {
const { workspace, projectName, architect } = resolveWorkspace(options, host);
if ('ngsscbuild' in architect) {
context.logger.info(`Skipping adding ngsscbuild target to angular.json, as it already exists in project ${projectName}.`);
return schematics.noop();
return (_host, context) => workspace.updateWorkspace((workspace) => {
const project = workspace.projects.get(options.project);
if (!project) {
return;
}
architect.ngsscbuild = {
const target = project.targets.get('ngsscbuild');
if (target) {
context.logger.info(`Skipping adding ngsscbuild target to angular.json, as it already exists in project ${options.project}.`);
return;
}
project.targets.add({
name: 'ngsscbuild',
builder: 'angular-server-side-configuration:ngsscbuild',
options: {
additionalEnvironmentVariables: options.additionalEnvironmentVariables
? options.additionalEnvironmentVariables.split(',').map(e => e.trim()) : [],
browserTarget: `${projectName}:build`,
? options.additionalEnvironmentVariables.split(',').map((e) => e.trim())
: [],
browserTarget: `${options.project}:build`,
ngsscEnvironmentFile: options.ngsscEnvironmentFile,
},
// tslint:disable-next-line: object-literal-sort-keys
configurations: {
production: {
browserTarget: `${projectName}:build:production`,
browserTarget: `${options.project}:build:production`,
},
},
};
return config.updateWorkspace(workspace);
};
});
});
}
function addImportAndDescriptionToEnvironmentFile(options) {
return (host, context) => {
const { projectRoot } = resolveWorkspace(options, host);
const normalizedPath = core.join(core.normalize(projectRoot), options.ngsscEnvironmentFile);
return async (host, context) => {
const { project } = await resolveWorkspace(options, host);
const normalizedPath = core.join(core.normalize(project.root), options.ngsscEnvironmentFile);
const file = host.get(normalizedPath);

@@ -87,3 +91,2 @@ if (!file) {

return (host, context) => {
const { projectName } = resolveWorkspace(options, host);
const pkgPath = '/package.json';

@@ -94,3 +97,3 @@ const buffer = host.read(pkgPath);

}
const pkg = { scripts: {}, ...JSON.parse(buffer.toString()) };
const pkg = Object.assign({ scripts: {} }, JSON.parse(buffer.toString()));
if ('build:ngssc' in pkg.scripts) {

@@ -100,3 +103,3 @@ context.logger.info(`Skipping adding script to package.json, as it already exists.`);

}
pkg.scripts['build:ngssc'] = `ng run ${projectName}:ngsscbuild:production`;
pkg.scripts['build:ngssc'] = `ng run ${options.project}:ngsscbuild:production`;
host.overwrite(pkgPath, JSON.stringify(pkg, null, 2));

@@ -106,9 +109,10 @@ };

function addPlaceholderToIndexHtml(options) {
return (host, context) => {
const { architect, projectName } = resolveWorkspace(options, host);
const build = architect.build;
return async (host, context) => {
var _a;
const { project } = await resolveWorkspace(options, host);
const build = project.targets.get('build');
if (!build) {
throw new schematics.SchematicsException(`Expected a build target in project ${projectName}!`);
throw new schematics.SchematicsException(`Expected a build target in project ${options.project}!`);
}
const indexPath = build.options.index || 'src/index.html';
const indexPath = ((_a = build.options) === null || _a === void 0 ? void 0 : _a.index) || 'src/index.html';
const indexHtml = host.get(indexPath);

@@ -124,3 +128,4 @@ if (!indexHtml) {

const insertIndex = indexHtmlContent.includes('</title>')
? indexHtmlContent.indexOf('</title>') + 9 : indexHtmlContent.indexOf('</head>');
? indexHtmlContent.indexOf('</title>') + 9
: indexHtmlContent.indexOf('</head>');
const insertion = new change.InsertChange(indexHtml.path, insertIndex, ' <!--CONFIG-->\n');

@@ -132,12 +137,11 @@ const recorder = host.beginUpdate(indexHtml.path);

}
function resolveWorkspace(options, host) {
const workspace = config.getWorkspace(host);
const projectName = options.project || workspace.defaultProject || Object.keys(workspace.projects)[0];
const { architect, root } = workspace.projects[projectName];
if (!architect) {
throw new schematics.SchematicsException(`Expected project ${projectName} to have an architect section!`);
async function resolveWorkspace(options, host) {
const workspace$1 = await workspace.getWorkspace(host);
const project = workspace$1.projects.get(options.project);
if (!project) {
throw new schematics.SchematicsException(`Project ${options.project} not found!`);
}
return { workspace, projectName, architect, projectRoot: root };
return { workspace: workspace$1, project };
}
exports.ngAdd = ngAdd;

@@ -45,2 +45,2 @@ {

}
}
}

@@ -7,3 +7,3 @@ 'use strict';

var schematics = require('@angular-devkit/schematics');
var config = require('@schematics/angular/utility/config');
var workspace = require('@schematics/angular/utility/workspace');
var change = require('@schematics/angular/utility/change');

@@ -20,30 +20,34 @@

function addNgsscTargetToWorkspace(options) {
return (host, context) => {
const { workspace, projectName, architect } = resolveWorkspace(options, host);
if ('ngsscbuild' in architect) {
context.logger.info(`Skipping adding ngsscbuild target to angular.json, as it already exists in project ${projectName}.`);
return schematics.noop();
return (_host, context) => workspace.updateWorkspace((workspace) => {
const project = workspace.projects.get(options.project);
if (!project) {
return;
}
architect.ngsscbuild = {
const target = project.targets.get('ngsscbuild');
if (target) {
context.logger.info(`Skipping adding ngsscbuild target to angular.json, as it already exists in project ${options.project}.`);
return;
}
project.targets.add({
name: 'ngsscbuild',
builder: 'angular-server-side-configuration:ngsscbuild',
options: {
additionalEnvironmentVariables: options.additionalEnvironmentVariables
? options.additionalEnvironmentVariables.split(',').map(e => e.trim()) : [],
browserTarget: `${projectName}:build`,
? options.additionalEnvironmentVariables.split(',').map((e) => e.trim())
: [],
browserTarget: `${options.project}:build`,
ngsscEnvironmentFile: options.ngsscEnvironmentFile,
},
// tslint:disable-next-line: object-literal-sort-keys
configurations: {
production: {
browserTarget: `${projectName}:build:production`,
browserTarget: `${options.project}:build:production`,
},
},
};
return config.updateWorkspace(workspace);
};
});
});
}
function addImportAndDescriptionToEnvironmentFile(options) {
return (host, context) => {
const { projectRoot } = resolveWorkspace(options, host);
const normalizedPath = core.join(core.normalize(projectRoot), options.ngsscEnvironmentFile);
return async (host, context) => {
const { project } = await resolveWorkspace(options, host);
const normalizedPath = core.join(core.normalize(project.root), options.ngsscEnvironmentFile);
const file = host.get(normalizedPath);

@@ -87,3 +91,2 @@ if (!file) {

return (host, context) => {
const { projectName } = resolveWorkspace(options, host);
const pkgPath = '/package.json';

@@ -94,3 +97,3 @@ const buffer = host.read(pkgPath);

}
const pkg = { scripts: {}, ...JSON.parse(buffer.toString()) };
const pkg = Object.assign({ scripts: {} }, JSON.parse(buffer.toString()));
if ('build:ngssc' in pkg.scripts) {

@@ -100,3 +103,3 @@ context.logger.info(`Skipping adding script to package.json, as it already exists.`);

}
pkg.scripts['build:ngssc'] = `ng run ${projectName}:ngsscbuild:production`;
pkg.scripts['build:ngssc'] = `ng run ${options.project}:ngsscbuild:production`;
host.overwrite(pkgPath, JSON.stringify(pkg, null, 2));

@@ -106,9 +109,10 @@ };

function addPlaceholderToIndexHtml(options) {
return (host, context) => {
const { architect, projectName } = resolveWorkspace(options, host);
const build = architect.build;
return async (host, context) => {
var _a;
const { project } = await resolveWorkspace(options, host);
const build = project.targets.get('build');
if (!build) {
throw new schematics.SchematicsException(`Expected a build target in project ${projectName}!`);
throw new schematics.SchematicsException(`Expected a build target in project ${options.project}!`);
}
const indexPath = build.options.index || 'src/index.html';
const indexPath = ((_a = build.options) === null || _a === void 0 ? void 0 : _a.index) || 'src/index.html';
const indexHtml = host.get(indexPath);

@@ -124,3 +128,4 @@ if (!indexHtml) {

const insertIndex = indexHtmlContent.includes('</title>')
? indexHtmlContent.indexOf('</title>') + 9 : indexHtmlContent.indexOf('</head>');
? indexHtmlContent.indexOf('</title>') + 9
: indexHtmlContent.indexOf('</head>');
const insertion = new change.InsertChange(indexHtml.path, insertIndex, ' <!--CONFIG-->\n');

@@ -132,10 +137,9 @@ const recorder = host.beginUpdate(indexHtml.path);

}
function resolveWorkspace(options, host) {
const workspace = config.getWorkspace(host);
const projectName = options.project || workspace.defaultProject || Object.keys(workspace.projects)[0];
const { architect, root } = workspace.projects[projectName];
if (!architect) {
throw new schematics.SchematicsException(`Expected project ${projectName} to have an architect section!`);
async function resolveWorkspace(options, host) {
const workspace$1 = await workspace.getWorkspace(host);
const project = workspace$1.projects.get(options.project);
if (!project) {
throw new schematics.SchematicsException(`Project ${options.project} not found!`);
}
return { workspace, projectName, architect, projectRoot: root };
return { workspace: workspace$1, project };
}

@@ -145,12 +149,14 @@

function updateToV8() {
return (tree) => {
return async (tree) => {
const ngssc = tryReadNgsscJson(tree);
const variant = findAndPatchVariantFromFiles(tree);
const workspace$1 = await workspace.getWorkspace(tree);
const projects = Array.from(workspace$1.projects.keys());
return schematics.chain([
ngAdd({
...projects.map((project) => ngAdd({
additionalEnvironmentVariables: (ngssc.environmentVariables || []).join(','),
ngsscEnvironmentFile: 'src/environments/environment.prod.ts',
project: '',
project,
variant,
}),
})),
removeNgsscJson(),

@@ -162,22 +168,22 @@ checkNgsscUsageInScripts(),

function updateToV9() {
return (tree, context) => {
const workspace = config.getWorkspace(tree);
context.logger.info(`Removing ngsscbuild entry 'aotSupport', since it is no longer necessary for Ivy.`);
Object.keys(workspace.projects)
.filter(p => workspace.projects[p].architect &&
workspace.projects[p].architect.ngsscbuild)
.forEach(p => {
const ngsscbuild = workspace.projects[p].architect.ngsscbuild;
if ('aotSupport' in ngsscbuild.options) {
delete ngsscbuild.options.aotSupport;
context.logger.info(` - Removed from ${p} ngsscbuild options`);
}
Object.keys(ngsscbuild.configurations || {})
.filter(c => 'aotSupport' in ngsscbuild.configurations[c])
.forEach(c => {
delete ngsscbuild.configurations[c].aotSupport;
context.logger.info(` - Removed from ${p} ngsscbuild configuration ${c}`);
return (_tree, context) => {
return workspace.updateWorkspace((workspace) => {
context.logger.info(`Removing ngsscbuild entry 'aotSupport', since it is no longer necessary for Ivy.`);
workspace.projects.forEach((project, name) => {
const ngsscbuild = project.targets.get('ngsscbuild');
if (!ngsscbuild || !ngsscbuild.options) {
return;
}
if ('aotSupport' in ngsscbuild.options) {
delete ngsscbuild.options.aotSupport;
context.logger.info(` - Removed from ${name} ngsscbuild options`);
}
Object.keys(ngsscbuild.configurations || {})
.filter((c) => 'aotSupport' in ngsscbuild.configurations[c])
.forEach((c) => {
delete ngsscbuild.configurations[c].aotSupport;
context.logger.info(` - Removed from ${name} ngsscbuild configuration ${c}`);
});
});
});
return config.updateWorkspace(workspace);
};

@@ -190,3 +196,5 @@ }

tree.visit((path, entry) => {
if (core.basename(path).indexOf('Dockerfile') >= 0 && entry && entry.content.toString().match(downloadUrlRegex)) {
if (core.basename(path).indexOf('Dockerfile') >= 0 &&
entry &&
entry.content.toString().match(downloadUrlRegex)) {
const content = entry.content

@@ -232,3 +240,3 @@ .toString()

function checkNgsscUsageInScripts() {
return (tree, context) => {
return async (tree, context) => {
const packageJson = tree.read('/package.json');

@@ -239,10 +247,8 @@ if (!packageJson) {

const pkg = JSON.parse(packageJson.toString('utf8'));
const ngsscUsedInScripts = Object
.keys(pkg.scripts || {})
.some(k => pkg.scripts[k].includes('ngssc '));
const ngsscUsedInScripts = Object.keys(pkg.scripts || {}).some((k) => pkg.scripts[k].includes('ngssc '));
if (!ngsscUsedInScripts) {
return;
}
const workspace = config.getWorkspace(tree);
const projectName = workspace.defaultProject || Object.keys(workspace.projects)[0];
const workspace$1 = await workspace.getWorkspace(tree);
const projectName = Array.from(workspace$1.projects.keys())[0];
context.logger.info('Please remove the ngssc usage from your scripts.');

@@ -249,0 +255,0 @@ context.logger.info(`To run the ngssc build, run the command \`ng run ${projectName}:ngsscbuild:production\`.`);

@@ -143,4 +143,4 @@ 'use strict';

walk(directory, '**/ngssc.json')
.map(f => path.dirname(f))
.forEach(d => insertWithNgssc(d, !!options.dryRun));
.map((f) => path.dirname(f))
.forEach((d) => insertWithNgssc(d, !!options.dryRun));
}

@@ -159,3 +159,3 @@ else {

log(`Populated environment variables (Variant: ${ngssc.variant}, ${ngsscPath})`);
Object.keys(populatedVariables).forEach(k => ` ${k}: ${populatedVariables[k]}`);
Object.keys(populatedVariables).forEach((k) => ` ${k}: ${populatedVariables[k]}`);
const iife = generateIife(ngssc.variant, populatedVariables);

@@ -173,3 +173,3 @@ const htmlPattern = ngssc.filePattern || 'index.html';

else {
htmlFiles.forEach(f => insertIntoHtml(f, iife));
htmlFiles.forEach((f) => insertIntoHtml(f, iife));
}

@@ -179,9 +179,9 @@ }

const populatedVariables = {};
variables.forEach(v => populatedVariables[v] = v in process.env ? process.env[v] || '' : null);
variables.forEach((v) => (populatedVariables[v] = v in process.env ? process.env[v] || '' : null));
return populatedVariables;
}
function generateIife(variant, populatedVariables) {
const iife = variant === 'NG_ENV' ?
`(function(self){self.NG_ENV=${JSON.stringify(populatedVariables)};})(window)` :
`(function(self){self.process=${JSON.stringify({ env: populatedVariables })};})(window)`;
const iife = variant === 'NG_ENV'
? `(function(self){self.NG_ENV=${JSON.stringify(populatedVariables)};})(window)`
: `(function(self){self.process=${JSON.stringify({ env: populatedVariables })};})(window)`;
return `<!--ngssc--><script>${iife}</script><!--/ngssc-->`;

@@ -208,4 +208,4 @@ }

return fs.readdirSync(directory)
.map(f => `${directory}/${f}`)
.map(f => {
.map((f) => `${directory}/${f}`)
.map((f) => {
const stat = fs.lstatSync(f);

@@ -212,0 +212,0 @@ if (stat.isDirectory()) {

@@ -139,4 +139,4 @@ import { readdirSync, lstatSync, existsSync, readFileSync, writeFileSync } from 'fs';

walk(directory, '**/ngssc.json')
.map(f => dirname(f))
.forEach(d => insertWithNgssc(d, !!options.dryRun));
.map((f) => dirname(f))
.forEach((d) => insertWithNgssc(d, !!options.dryRun));
}

@@ -155,3 +155,3 @@ else {

log(`Populated environment variables (Variant: ${ngssc.variant}, ${ngsscPath})`);
Object.keys(populatedVariables).forEach(k => ` ${k}: ${populatedVariables[k]}`);
Object.keys(populatedVariables).forEach((k) => ` ${k}: ${populatedVariables[k]}`);
const iife = generateIife(ngssc.variant, populatedVariables);

@@ -169,3 +169,3 @@ const htmlPattern = ngssc.filePattern || 'index.html';

else {
htmlFiles.forEach(f => insertIntoHtml(f, iife));
htmlFiles.forEach((f) => insertIntoHtml(f, iife));
}

@@ -175,9 +175,9 @@ }

const populatedVariables = {};
variables.forEach(v => populatedVariables[v] = v in process.env ? process.env[v] || '' : null);
variables.forEach((v) => (populatedVariables[v] = v in process.env ? process.env[v] || '' : null));
return populatedVariables;
}
function generateIife(variant, populatedVariables) {
const iife = variant === 'NG_ENV' ?
`(function(self){self.NG_ENV=${JSON.stringify(populatedVariables)};})(window)` :
`(function(self){self.process=${JSON.stringify({ env: populatedVariables })};})(window)`;
const iife = variant === 'NG_ENV'
? `(function(self){self.NG_ENV=${JSON.stringify(populatedVariables)};})(window)`
: `(function(self){self.process=${JSON.stringify({ env: populatedVariables })};})(window)`;
return `<!--ngssc--><script>${iife}</script><!--/ngssc-->`;

@@ -204,4 +204,4 @@ }

return readdirSync(directory)
.map(f => `${directory}/${f}`)
.map(f => {
.map((f) => `${directory}/${f}`)
.map((f) => {
const stat = lstatSync(f);

@@ -208,0 +208,0 @@ if (stat.isDirectory()) {