This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
/// <reference types="node" />
export declare function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string;

View File

@@ -0,0 +1,18 @@
---
labels: ['configuration']
description: 'A function for repacing env variables in configuration settings'
---
API:
```ts
function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string;
```
Usage:
```ts
import { envReplace } from '@pnpm/config.env-replace'
envReplace('${foo}', process.env)
```

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.envReplace = void 0;
const ENV_EXPR = /(?<!\\)(\\*)\$\{([^${}]+)\}/g;
function envReplace(settingValue, env) {
return settingValue.replace(ENV_EXPR, replaceEnvMatch.bind(null, env));
}
exports.envReplace = envReplace;
function replaceEnvMatch(env, orig, escape, name) {
if (escape.length % 2) {
return orig.slice((escape.length + 1) / 2);
}
const envValue = getEnvValue(env, name);
if (envValue === undefined) {
throw new Error(`Failed to replace env in config: ${orig}`);
}
return `${(escape.slice(escape.length / 2))}${envValue}`;
}
const ENV_VALUE = /([^:-]+)(:?)-(.+)/;
function getEnvValue(env, name) {
const matched = name.match(ENV_VALUE);
if (!matched)
return env[name];
const [, variableName, colon, fallback] = matched;
if (Object.prototype.hasOwnProperty.call(env, variableName)) {
return !env[variableName] && colon ? fallback : env[variableName];
}
return fallback;
}
//# sourceMappingURL=env-replace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"env-replace.js","sourceRoot":"","sources":["../env-replace.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAG,8BAA8B,CAAA;AAE/C,SAAgB,UAAU,CAAC,YAAoB,EAAE,GAAsB;IACrE,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;AACxE,CAAC;AAFD,gCAEC;AAED,SAAS,eAAe,CAAE,GAAsB,EAAE,IAAY,EAAE,MAAc,EAAE,IAAY;IAC1F,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;KAC3C;IACD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACvC,IAAI,QAAQ,KAAK,SAAS,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAA;KAC5D;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,EAAE,CAAA;AAC1D,CAAC;AAED,MAAM,SAAS,GAAG,mBAAmB,CAAA;AAErC,SAAS,WAAW,CAAE,GAAsB,EAAE,IAAY;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACrC,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAA;IACjD,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE;QAC3D,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;KAClE;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const env_replace_1 = require("./env-replace");
const ENV = {
foo: 'foo_value',
bar: 'bar_value',
zoo: '',
};
test.each([
['-${foo}-${bar}', '-foo_value-bar_value'],
['\\${foo}', '${foo}'],
['\\${zoo}', '${zoo}'],
['\\\\${foo}', '\\foo_value'],
['-${foo-fallback-value}-${bar:-fallback-value}', '-foo_value-bar_value'],
['-${qar-fallback-value}-${zoo-fallback-value}', '-fallback-value-'],
['-${qar-fallback-value}-${zoo:-fallback-for-empty-value}', '-fallback-value-fallback-for-empty-value']
])('success %s => %s', (settingValue, expected) => {
const actual = (0, env_replace_1.envReplace)(settingValue, ENV);
expect(actual).toEqual(expected);
});
test('fail when the env variable is not found', () => {
expect(() => (0, env_replace_1.envReplace)('${baz}', ENV)).toThrow(`Failed to replace env in config: \${baz}`);
expect(() => (0, env_replace_1.envReplace)('${foo-}', ENV)).toThrow(`Failed to replace env in config: \${foo-}`);
expect(() => (0, env_replace_1.envReplace)('${foo:-}', ENV)).toThrow(`Failed to replace env in config: \${foo:-}`);
});
//# sourceMappingURL=env-replace.spec.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"env-replace.spec.js","sourceRoot":"","sources":["../env-replace.spec.ts"],"names":[],"mappings":";;AAAA,+CAA2C;AAE3C,MAAM,GAAG,GAAG;IACV,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,EAAE;CACR,CAAA;AAED,IAAI,CAAC,IAAI,CAAC;IACR,CAAC,gBAAgB,EAAE,sBAAsB,CAAC;IAC1C,CAAC,UAAU,EAAE,QAAQ,CAAC;IACtB,CAAC,UAAU,EAAE,QAAQ,CAAC;IACtB,CAAC,YAAY,EAAE,aAAa,CAAC;IAC7B,CAAC,+CAA+C,EAAE,sBAAsB,CAAC;IACzE,CAAC,8CAA8C,EAAE,kBAAkB,CAAC;IACpE,CAAC,yDAAyD,EAAE,0CAA0C,CAAC;CACxG,CAAC,CAAC,kBAAkB,EAAE,CAAC,YAAY,EAAE,QAAQ,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,IAAA,wBAAU,EAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IAC7C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,wBAAU,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC;IAC5F,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,wBAAU,EAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,2CAA2C,CAAC,CAAC;IAC9F,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,wBAAU,EAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;AAClG,CAAC,CAAC,CAAA"}

View File

@@ -0,0 +1 @@
export { envReplace } from './env-replace';

6
node_modules/@pnpm/config.env-replace/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.envReplace = void 0;
var env_replace_1 = require("./env-replace");
Object.defineProperty(exports, "envReplace", { enumerable: true, get: function () { return env_replace_1.envReplace; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}

View File

@@ -0,0 +1,7 @@
;
import * as overview_0 from '/Users/zoltan/Library/Caches/Bit/capsules/05f6140f72f7d4c5be56111dbe63734e37f4e9e4/pnpm.config_env-replace@1.1.0/dist/env-replace.docs.mdx';
export const compositions = [];
export const overview = [overview_0];
export const compositions_metadata = {"compositions":[]};

View File

@@ -0,0 +1,32 @@
{
"compilerOptions": {
"lib": [
"es2019",
"DOM",
"ES6",
"DOM.Iterable"
],
"target": "es2015",
"module": "CommonJS",
"jsx": "react",
"allowJs": true,
"composite": true,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"outDir": "dist",
"moduleResolution": "node",
"esModuleInterop": true,
"rootDir": ".",
"resolveJsonModule": true
},
"exclude": [
"dist",
"package.json"
],
"include": [
"**/*",
"**/*.json"
]
}

View File

@@ -0,0 +1,18 @@
---
labels: ['configuration']
description: 'A function for repacing env variables in configuration settings'
---
API:
```ts
function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string;
```
Usage:
```ts
import { envReplace } from '@pnpm/config.env-replace'
envReplace('${foo}', process.env)
```

View File

@@ -0,0 +1,27 @@
import { envReplace } from './env-replace';
const ENV = {
foo: 'foo_value',
bar: 'bar_value',
zoo: '',
}
test.each([
['-${foo}-${bar}', '-foo_value-bar_value'],
['\\${foo}', '${foo}'],
['\\${zoo}', '${zoo}'],
['\\\\${foo}', '\\foo_value'],
['-${foo-fallback-value}-${bar:-fallback-value}', '-foo_value-bar_value'],
['-${qar-fallback-value}-${zoo-fallback-value}', '-fallback-value-'],
['-${qar-fallback-value}-${zoo:-fallback-for-empty-value}', '-fallback-value-fallback-for-empty-value']
])('success %s => %s', (settingValue, expected) => {
const actual = envReplace(settingValue, ENV);
expect(actual).toEqual(expected);
})
test('fail when the env variable is not found', () => {
expect(() => envReplace('${baz}', ENV)).toThrow(`Failed to replace env in config: \${baz}`);
expect(() => envReplace('${foo-}', ENV)).toThrow(`Failed to replace env in config: \${foo-}`);
expect(() => envReplace('${foo:-}', ENV)).toThrow(`Failed to replace env in config: \${foo:-}`);
})

28
node_modules/@pnpm/config.env-replace/env-replace.ts generated vendored Normal file
View File

@@ -0,0 +1,28 @@
const ENV_EXPR = /(?<!\\)(\\*)\$\{([^${}]+)\}/g
export function envReplace(settingValue: string, env: NodeJS.ProcessEnv): string {
return settingValue.replace(ENV_EXPR, replaceEnvMatch.bind(null, env))
}
function replaceEnvMatch (env: NodeJS.ProcessEnv, orig: string, escape: string, name: string): string {
if (escape.length % 2) {
return orig.slice((escape.length + 1) / 2)
}
const envValue = getEnvValue(env, name)
if (envValue === undefined) {
throw new Error(`Failed to replace env in config: ${orig}`)
}
return `${(escape.slice(escape.length / 2))}${envValue}`
}
const ENV_VALUE = /([^:-]+)(:?)-(.+)/
function getEnvValue (env: NodeJS.ProcessEnv, name: string): string {
const matched = name.match(ENV_VALUE)
if (!matched) return env[name]
const [, variableName, colon, fallback] = matched
if (Object.prototype.hasOwnProperty.call(env, variableName)) {
return !env[variableName] && colon ? fallback : env[variableName]
}
return fallback
}

1
node_modules/@pnpm/config.env-replace/index.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export { envReplace } from './env-replace';

31
node_modules/@pnpm/config.env-replace/package.json generated vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "@pnpm/config.env-replace",
"version": "1.1.0",
"homepage": "https://bit.cloud/pnpm/config/env-replace",
"main": "dist/index.js",
"componentId": {
"scope": "pnpm.config",
"name": "env-replace",
"version": "1.1.0"
},
"dependencies": {},
"devDependencies": {
"@types/jest": "26.0.20",
"@types/node": "12.20.4",
"@babel/runtime": "7.20.0"
},
"peerDependencies": {},
"license": "MIT",
"private": false,
"engines": {
"node": ">=12.22.0"
},
"repository": {
"type": "git",
"url": "https://github.com/pnpm/components"
},
"keywords": [],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
}

32
node_modules/@pnpm/config.env-replace/tsconfig.json generated vendored Normal file
View File

@@ -0,0 +1,32 @@
{
"compilerOptions": {
"lib": [
"es2019",
"DOM",
"ES6",
"DOM.Iterable"
],
"target": "es2015",
"module": "CommonJS",
"jsx": "react",
"allowJs": true,
"composite": true,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"outDir": "dist",
"moduleResolution": "node",
"esModuleInterop": true,
"rootDir": ".",
"resolveJsonModule": true
},
"exclude": [
"dist",
"package.json"
],
"include": [
"**/*",
"**/*.json"
]
}

29
node_modules/@pnpm/config.env-replace/types/asset.d.ts generated vendored Normal file
View File

@@ -0,0 +1,29 @@
declare module '*.png' {
const value: any;
export = value;
}
declare module '*.svg' {
import type { FunctionComponent, SVGProps } from 'react';
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
const src: string;
export default src;
}
// @TODO Gilad
declare module '*.jpg' {
const value: any;
export = value;
}
declare module '*.jpeg' {
const value: any;
export = value;
}
declare module '*.gif' {
const value: any;
export = value;
}
declare module '*.bmp' {
const value: any;
export = value;
}

42
node_modules/@pnpm/config.env-replace/types/style.d.ts generated vendored Normal file
View File

@@ -0,0 +1,42 @@
declare module '*.module.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.scss' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.sass' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.less' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.less' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.sass' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.scss' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.mdx' {
const component: any;
export default component;
}