env-safe-check 1.0.0 → 1.0.1
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/dist/index.d.ts +3 -0
- package/{src/validate.ts → dist/index.js} +7 -7
- package/package.json +10 -4
- package/.github/workflows/npm-publish.yml +0 -38
- package/scripts/patch-extensions.cjs +0 -32
- package/scripts/patch-extensions.js +0 -38
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -46
package/dist/index.d.ts
ADDED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
// src/validate.ts
|
|
2
|
+
function validateEnv(required) {
|
|
2
3
|
const missing = required.filter((key) => {
|
|
3
4
|
const value = process.env[key];
|
|
4
|
-
return value ===
|
|
5
|
+
return value === void 0 || value.trim() === "";
|
|
5
6
|
});
|
|
6
|
-
|
|
7
7
|
if (missing.length > 0) {
|
|
8
|
-
console.error("
|
|
9
|
-
|
|
8
|
+
console.error("\u274C Missing required environment variables:\n");
|
|
10
9
|
missing.forEach((key) => {
|
|
11
10
|
console.error(`- ${key}`);
|
|
12
11
|
});
|
|
13
|
-
|
|
14
12
|
console.error(
|
|
15
13
|
"\nPlease define them in your .env file or environment config."
|
|
16
14
|
);
|
|
17
|
-
|
|
18
15
|
process.exit(1);
|
|
19
16
|
}
|
|
20
17
|
}
|
|
18
|
+
export {
|
|
19
|
+
validateEnv
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "env-safe-check",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
11
|
"test": "echo \"hello world\"",
|
|
8
|
-
"build": "
|
|
12
|
+
"build": "tsup src/index.ts --format esm --dts --out-dir dist",
|
|
13
|
+
"prepare": "npm run build"
|
|
9
14
|
},
|
|
10
15
|
"keywords": [],
|
|
11
16
|
"author": "",
|
|
@@ -13,6 +18,7 @@
|
|
|
13
18
|
"description": "",
|
|
14
19
|
"devDependencies": {
|
|
15
20
|
"typescript": "^5.9.3",
|
|
16
|
-
"@types/node": "^20.6.5"
|
|
21
|
+
"@types/node": "^20.6.5",
|
|
22
|
+
"tsup": "^6.6.0"
|
|
17
23
|
}
|
|
18
24
|
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Node.js Package
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
release:
|
|
8
|
-
types: [created]
|
|
9
|
-
workflow_dispatch: {}
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
build:
|
|
13
|
-
# Only run automatically for the `main` branch or when a release is created.
|
|
14
|
-
if: github.ref == 'refs/heads/main' || github.event_name == 'release' || github.event_name == 'workflow_dispatch'
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v4
|
|
18
|
-
- uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: 20
|
|
21
|
-
- run: npm ci
|
|
22
|
-
- run: npm test
|
|
23
|
-
|
|
24
|
-
publish-npm:
|
|
25
|
-
needs: build
|
|
26
|
-
# Only publish when the run is for `main` or a release (keeps publishes scoped to main).
|
|
27
|
-
if: github.ref == 'refs/heads/main' || github.event_name == 'release' || github.event_name == 'workflow_dispatch'
|
|
28
|
-
runs-on: ubuntu-latest
|
|
29
|
-
steps:
|
|
30
|
-
- uses: actions/checkout@v4
|
|
31
|
-
- uses: actions/setup-node@v4
|
|
32
|
-
with:
|
|
33
|
-
node-version: 20
|
|
34
|
-
registry-url: https://registry.npmjs.org/
|
|
35
|
-
- run: npm ci
|
|
36
|
-
- run: npm publish
|
|
37
|
-
env:
|
|
38
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
function walk(dir) {
|
|
5
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
6
|
-
for (const entry of entries) {
|
|
7
|
-
const full = path.join(dir, entry.name);
|
|
8
|
-
if (entry.isDirectory()) walk(full);
|
|
9
|
-
else if (entry.isFile() && full.endsWith('.js')) patchFile(full);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function patchFile(file) {
|
|
14
|
-
let src = fs.readFileSync(file, 'utf8');
|
|
15
|
-
src = src.replace(/(from\s+|import\()(["'])(\.\/[^"'\)]+?)\2/g, (m, p1, q, p2) => {
|
|
16
|
-
if (/\.[a-zA-Z0-9]+$/.test(p2)) return m;
|
|
17
|
-
return `${p1}${q}${p2}.js${q}`;
|
|
18
|
-
});
|
|
19
|
-
src = src.replace(/(export\s+[^;]*?from\s+)(["'])(\.\/[^"']+?)\2/g, (m, p1, q, p2) => {
|
|
20
|
-
if (/\.[a-zA-Z0-9]+$/.test(p2)) return m;
|
|
21
|
-
return `${p1}${q}${p2}.js${q}`;
|
|
22
|
-
});
|
|
23
|
-
fs.writeFileSync(file, src, 'utf8');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const dist = path.join(__dirname, '..', 'dist');
|
|
27
|
-
if (!fs.existsSync(dist)) {
|
|
28
|
-
console.error('dist directory not found; run tsc first');
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
walk(dist);
|
|
32
|
-
console.log('Patched imports to include .js extensions in', dist);
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
function walk(dir) {
|
|
5
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
6
|
-
for (const entry of entries) {
|
|
7
|
-
const full = path.join(dir, entry.name);
|
|
8
|
-
if (entry.isDirectory()) walk(full);
|
|
9
|
-
else if (entry.isFile() && full.endsWith('.js')) patchFile(full);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function patchFile(file) {
|
|
14
|
-
let src = fs.readFileSync(file, 'utf8');
|
|
15
|
-
// Replace import/export specifiers that are relative and have no extension
|
|
16
|
-
// Examples: import {x} from "./foo" -> ./foo.js
|
|
17
|
-
// export * from './bar' -> ./bar.js
|
|
18
|
-
src = src.replace(/(from\s+|import\()(["'])(\.\/[^"'\)]+?)\2/g, (m, p1, q, p2) => {
|
|
19
|
-
// p2 is like ./module or ../module/sub
|
|
20
|
-
// If it already ends with an extension, leave it
|
|
21
|
-
if (/\.[a-zA-Z0-9]+$/.test(p2)) return m;
|
|
22
|
-
return `${p1}${q}${p2}.js${q}`;
|
|
23
|
-
});
|
|
24
|
-
// also handle export ... from '...'
|
|
25
|
-
src = src.replace(/(export\s+[^;]*?from\s+)(["'])(\.\/[^"']+?)\2/g, (m, p1, q, p2) => {
|
|
26
|
-
if (/\.[a-zA-Z0-9]+$/.test(p2)) return m;
|
|
27
|
-
return `${p1}${q}${p2}.js${q}`;
|
|
28
|
-
});
|
|
29
|
-
fs.writeFileSync(file, src, 'utf8');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const dist = path.join(__dirname, '..', 'dist');
|
|
33
|
-
if (!fs.existsSync(dist)) {
|
|
34
|
-
console.error('dist directory not found; run tsc first');
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
walk(dist);
|
|
38
|
-
console.log('Patched imports to include .js extensions in', dist);
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { validateEnv } from "./validate";
|
package/tsconfig.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// File Layout
|
|
5
|
-
// "rootDir": "./src",
|
|
6
|
-
// "outDir": "./dist",
|
|
7
|
-
|
|
8
|
-
// Environment Settings
|
|
9
|
-
// See also https://aka.ms/tsconfig/module
|
|
10
|
-
"module": "esnext",
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
"target": "esnext",
|
|
13
|
-
"outDir": "./dist",
|
|
14
|
-
"types": ["node"],
|
|
15
|
-
// For nodejs:
|
|
16
|
-
// "lib": ["esnext"],
|
|
17
|
-
// "types": ["node"],
|
|
18
|
-
// and npm install -D @types/node
|
|
19
|
-
|
|
20
|
-
// Other Outputs
|
|
21
|
-
"sourceMap": true,
|
|
22
|
-
"declaration": true,
|
|
23
|
-
"declarationMap": true,
|
|
24
|
-
|
|
25
|
-
// Stricter Typechecking Options
|
|
26
|
-
"noUncheckedIndexedAccess": true,
|
|
27
|
-
"exactOptionalPropertyTypes": true,
|
|
28
|
-
|
|
29
|
-
// Style Options
|
|
30
|
-
// "noImplicitReturns": true,
|
|
31
|
-
// "noImplicitOverride": true,
|
|
32
|
-
// "noUnusedLocals": true,
|
|
33
|
-
// "noUnusedParameters": true,
|
|
34
|
-
// "noFallthroughCasesInSwitch": true,
|
|
35
|
-
// "noPropertyAccessFromIndexSignature": true,
|
|
36
|
-
|
|
37
|
-
// Recommended Options
|
|
38
|
-
"strict": true,
|
|
39
|
-
"jsx": "react-jsx",
|
|
40
|
-
"verbatimModuleSyntax": true,
|
|
41
|
-
"isolatedModules": true,
|
|
42
|
-
"noUncheckedSideEffectImports": true,
|
|
43
|
-
"moduleDetection": "force",
|
|
44
|
-
"skipLibCheck": true,
|
|
45
|
-
}
|
|
46
|
-
}
|