-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevcheck.mjs
More file actions
103 lines (94 loc) · 4.27 KB
/
Copy pathdevcheck.mjs
File metadata and controls
103 lines (94 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* @Project: @cldmv/slothlet
* @Filename: /devcheck.mjs
* @Date: 2025-09-09T08:06:19-07:00 (1757430379)
* @Author: Nate Corcoran <CLDMV>
* @Email: <Shinrai@users.noreply.github.com>
* -----
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
* @Last modified time: 2026-03-01 20:21:36 -08:00 (1772425296)
* -----
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
*/
import { existsSync } from "node:fs";
import { fileURLToPath } from "node:url";
import path from "node:path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const srcPath = path.join(__dirname, "src");
const distPath = path.join(__dirname, "dist");
// Detect if we're running in a CI environment
const isCI = !!(
process.env.CI || // Generic CI flag
process.env.GITHUB_ACTIONS || // GitHub Actions
process.env.TRAVIS || // Travis CI
process.env.CIRCLECI || // CircleCI
process.env.GITLAB_CI || // GitLab CI
process.env.BUILDKITE || // Buildkite
process.env.JENKINS_URL || // Jenkins
process.env.TF_BUILD // Azure DevOps
);
if (existsSync(srcPath) && !existsSync(distPath) && !isCI) {
const nodeEnv = process.env.NODE_ENV?.toLowerCase();
// Dev resolver conditions arrive either via NODE_OPTIONS (env) or on the CLI, where Node puts
// them in process.execArgv — which is also how vitest passes conditions to its workers. Fold
// both into one haystack so the CLI/worker form is detected, not just the env form. (#270)
const conditionFlags = (process.env.NODE_OPTIONS || "") + " " + process.execArgv.join(" ");
// Detect an installed copy by a `node_modules` segment anywhere above this file. Matching only
// basename(dirname(__dirname)) misses a scoped install — node_modules/@cldmv/slothlet, whose
// parent is the `@cldmv` scope dir, not `node_modules`. (#270)
const isInstalledPackage = __dirname.split(path.sep).includes("node_modules");
// Parse conditions from NODE_OPTIONS / execArgv
const hasSlothletDev = conditionFlags.includes("slothlet-dev");
const hasGenericDev = conditionFlags.includes("--conditions=development") || conditionFlags.includes("--conditions development");
const hasDevEnv = nodeEnv === "dev" || nodeEnv === "development";
// Only check if we're in the slothlet repo (not installed in node_modules)
if (!isInstalledPackage && !hasSlothletDev) {
let errorMessage;
// Determine which error message to show based on current state
if (hasDevEnv && hasGenericDev) {
// They have generic dev settings - tell them to switch to slothlet-dev
errorMessage =
"❌ Incorrect development environment detected!\n" +
"📁 You have generic development settings (NODE_ENV=development, --conditions=development).\n" +
"\n" +
"⚠️ This causes slothlet to load from src/ which breaks tests and builds!\n" +
"\n" +
"🔧 Switch to slothlet-specific development settings:\n" +
" Windows (cmd):\n" +
" set NODE_OPTIONS=--conditions=slothlet-dev\n" +
"\n" +
" Windows (PowerShell):\n" +
" $env:NODE_OPTIONS='--conditions=slothlet-dev'\n" +
"\n" +
" Unix/Linux/macOS:\n" +
" export NODE_OPTIONS=--conditions=slothlet-dev\n" +
"\n" +
"💡 Using 'slothlet-dev' prevents conflicts with apps that use slothlet.";
} else {
// They don't have proper settings at all
errorMessage =
"❌ Development environment not properly configured!\n" +
"📁 Source folder detected but NODE_ENV/NODE_OPTIONS not set for slothlet development.\n" +
"\n" +
"🔧 To fix this, run one of these commands:\n" +
" Windows (cmd):\n" +
" set NODE_ENV=development\n" +
" set NODE_OPTIONS=--conditions=slothlet-dev\n" +
"\n" +
" Windows (PowerShell):\n" +
" $env:NODE_ENV='development'\n" +
" $env:NODE_OPTIONS='--conditions=slothlet-dev'\n" +
"\n" +
" Unix/Linux/macOS:\n" +
" export NODE_ENV=development\n" +
" export NODE_OPTIONS=--conditions=slothlet-dev\n" +
"\n" +
"💡 This ensures slothlet loads from src/ instead of dist/ for development.\n" +
"🔧 Using 'slothlet-dev' prevents conflicts with consumer development settings.\n" +
"🚀 CI environments automatically skip this check.";
}
console.error(errorMessage);
process.exit(1);
}
}