@slim-lang/core 1.2.3 → 1.2.5
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/package.json +1 -1
- package/run-dev-slim.js +4 -2
- package/run-slim.js +2 -1
- package/src/bin/config.default.json +2 -1
- package/src/compile.js +9 -9
- package/src/modulePaths.js +38 -11
- package/src/test-runner.js +3 -2
- package/src/transform.js +2 -2
package/package.json
CHANGED
package/run-dev-slim.js
CHANGED
|
@@ -12,7 +12,8 @@ const config = JSON.parse(
|
|
|
12
12
|
fs.readFileSync("slimconfig.json", "utf8")
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const distDir = typeof config.dist === "string" && config.dist.trim() ? config.dist : "slim-dist";
|
|
16
|
+
const entry = `${distDir}/${config.main}.js`;
|
|
16
17
|
const hot = process.argv.includes("--hot");
|
|
17
18
|
|
|
18
19
|
let app = null;
|
|
@@ -114,6 +115,7 @@ async function rebuild() {
|
|
|
114
115
|
await rebuild();
|
|
115
116
|
|
|
116
117
|
const watchTarget = config.watch ?? ".";
|
|
118
|
+
const ignoreDirs = new RegExp(`(^|[\\\\/])(node_modules|${distDir}|\\.git)([\\\\/]|$)`);
|
|
117
119
|
|
|
118
120
|
const watcher = chokidar.watch(watchTarget, {
|
|
119
121
|
ignoreInitial: true,
|
|
@@ -121,7 +123,7 @@ const watcher = chokidar.watch(watchTarget, {
|
|
|
121
123
|
stabilityThreshold: 150,
|
|
122
124
|
pollInterval: 50
|
|
123
125
|
},
|
|
124
|
-
ignored: p =>
|
|
126
|
+
ignored: p => ignoreDirs.test(p)
|
|
125
127
|
});
|
|
126
128
|
|
|
127
129
|
watcher.on("all", (_, file) => {
|
package/run-slim.js
CHANGED
|
@@ -11,8 +11,9 @@ const root = process.cwd();
|
|
|
11
11
|
|
|
12
12
|
const config = JSON.parse(readFileSync(path.join(root, 'slimconfig.json'), 'utf8'));
|
|
13
13
|
const mainFile = config.main;
|
|
14
|
+
const distDir = typeof config.dist === 'string' && config.dist.trim() ? config.dist : 'slim-dist';
|
|
14
15
|
|
|
15
|
-
const dist = path.join(root,
|
|
16
|
+
const dist = path.join(root, distDir, `${mainFile}.js`);
|
|
16
17
|
const args = ['--enable-source-maps', '--no-warnings', dist];
|
|
17
18
|
|
|
18
19
|
const proc = spawn('node', args, { stdio: 'inherit' });
|
package/src/compile.js
CHANGED
|
@@ -7,7 +7,7 @@ import { readFile } from 'fs/promises';
|
|
|
7
7
|
import { Debug } from "./external/core.js";
|
|
8
8
|
import { stripComments } from "./parser.js";
|
|
9
9
|
import { UseError } from "./external/classErrors.js";
|
|
10
|
-
import { getDistPath, resolveSlimSource, PACKAGE_ROOT } from "./modulePaths.js";
|
|
10
|
+
import { getDistPath, resolveSlimSource, PACKAGE_ROOT, distDirName } from "./modulePaths.js";
|
|
11
11
|
|
|
12
12
|
const compiled = new Set()
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ let useStyle = "import"
|
|
|
19
19
|
|
|
20
20
|
function syncExternal() {
|
|
21
21
|
const srcExternal = path.join(PACKAGE_ROOT, "src/external")
|
|
22
|
-
const distExternal = path.resolve("
|
|
22
|
+
const distExternal = path.resolve(distDirName(), "external")
|
|
23
23
|
|
|
24
24
|
if (!fs.existsSync(srcExternal)) return
|
|
25
25
|
|
|
@@ -117,7 +117,7 @@ function compileFile(slimFile, isEntry = false, mainEntry = null) {
|
|
|
117
117
|
const { code: output, declarations: dts } = transform(code, abs, { jsdoc, declarations, check, uses: useStyle })
|
|
118
118
|
|
|
119
119
|
const outputPath = isEntry
|
|
120
|
-
? path.resolve(
|
|
120
|
+
? path.resolve(distDirName(), `${mainEntry}.js`)
|
|
121
121
|
: getDistPath(abs)
|
|
122
122
|
|
|
123
123
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true })
|
|
@@ -128,8 +128,8 @@ function compileFile(slimFile, isEntry = false, mainEntry = null) {
|
|
|
128
128
|
|
|
129
129
|
function cleanDist(slimFileClear) {
|
|
130
130
|
const keep = new Set([
|
|
131
|
-
path.resolve(
|
|
132
|
-
path.resolve("
|
|
131
|
+
path.resolve(distDirName(), `${slimFileClear}.js`),
|
|
132
|
+
path.resolve(distDirName(), "mappings.json"),
|
|
133
133
|
])
|
|
134
134
|
|
|
135
135
|
function addDirToKeep(dir) {
|
|
@@ -140,11 +140,11 @@ function cleanDist(slimFileClear) {
|
|
|
140
140
|
if (entry.isDirectory()) addDirToKeep(full)
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
addDirToKeep(path.resolve("
|
|
143
|
+
addDirToKeep(path.resolve(distDirName(), "external"))
|
|
144
144
|
|
|
145
145
|
for (const slimFile of compiled) {
|
|
146
146
|
if (slimFile === path.resolve(`${slimFileClear}.slim`)) {
|
|
147
|
-
keep.add(path.resolve(
|
|
147
|
+
keep.add(path.resolve(distDirName(), `${slimFileClear}.js`))
|
|
148
148
|
} else {
|
|
149
149
|
keep.add(getDistPath(slimFile))
|
|
150
150
|
}
|
|
@@ -173,7 +173,7 @@ function cleanDist(slimFileClear) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
walkAndClean(path.resolve(
|
|
176
|
+
walkAndClean(path.resolve(distDirName()))
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
function writeJsConfig() {
|
|
@@ -191,7 +191,7 @@ function writeJsConfig() {
|
|
|
191
191
|
strict: false,
|
|
192
192
|
skipLibCheck: true
|
|
193
193
|
},
|
|
194
|
-
include: [
|
|
194
|
+
include: [distDirName()]
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 4) + "\n")
|
package/src/modulePaths.js
CHANGED
|
@@ -7,20 +7,32 @@ const slimExtension = ".slim"
|
|
|
7
7
|
|
|
8
8
|
export const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
9
9
|
|
|
10
|
+
function readConfig() {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(fs.readFileSync(path.join(process.cwd(), "slimconfig.json"), "utf8"))
|
|
13
|
+
} catch {
|
|
14
|
+
return {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
let projectPackagesCache = null
|
|
11
19
|
export function projectPackagesDir() {
|
|
12
20
|
if (projectPackagesCache) return projectPackagesCache
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const config = JSON.parse(fs.readFileSync(path.join(process.cwd(), "slimconfig.json"), "utf8"))
|
|
17
|
-
if (typeof config.packages === "string" && config.packages.trim()) dir = config.packages
|
|
18
|
-
} catch {}
|
|
19
|
-
|
|
20
|
-
projectPackagesCache = path.resolve(dir)
|
|
22
|
+
const dir = readConfig().packages
|
|
23
|
+
projectPackagesCache = path.resolve(typeof dir === "string" && dir.trim() ? dir : "packages")
|
|
21
24
|
return projectPackagesCache
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
let distDirCache = null
|
|
28
|
+
export function distDirName() {
|
|
29
|
+
if (distDirCache) return distDirCache
|
|
30
|
+
|
|
31
|
+
const dir = readConfig().dist
|
|
32
|
+
distDirCache = typeof dir === "string" && dir.trim() ? dir : "slim-dist"
|
|
33
|
+
return distDirCache
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
function packageRoots() {
|
|
25
37
|
const projectPackages = projectPackagesDir()
|
|
26
38
|
const shippedPackages = path.join(PACKAGE_ROOT, "packages")
|
|
@@ -49,11 +61,26 @@ export function getDistPath(slimFile) {
|
|
|
49
61
|
const abs = path.resolve(slimFile)
|
|
50
62
|
const srcRoot = path.resolve("src")
|
|
51
63
|
const projectRoot = path.resolve(".")
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
const shippedPackages = path.join(PACKAGE_ROOT, "packages")
|
|
65
|
+
const projectPackages = projectPackagesDir()
|
|
66
|
+
|
|
67
|
+
let relative
|
|
68
|
+
|
|
69
|
+
if (isWithin(shippedPackages, abs)) {
|
|
70
|
+
relative = path.join("packages", path.relative(shippedPackages, abs))
|
|
71
|
+
} else if (isWithin(projectPackages, abs)) {
|
|
72
|
+
relative = path.join(path.basename(projectPackages), path.relative(projectPackages, abs))
|
|
73
|
+
} else if (isWithin(srcRoot, abs)) {
|
|
74
|
+
relative = path.relative(srcRoot, abs)
|
|
75
|
+
} else if (isWithin(projectRoot, abs)) {
|
|
76
|
+
relative = path.relative(projectRoot, abs)
|
|
77
|
+
} else {
|
|
78
|
+
// Drop leading "../" so out-of-project sources can't escape the dist dir.
|
|
79
|
+
const stripped = path.relative(projectRoot, abs).split(path.sep).filter(seg => seg !== "..")
|
|
80
|
+
relative = stripped.length ? path.join(...stripped) : path.basename(abs)
|
|
81
|
+
}
|
|
55
82
|
|
|
56
|
-
return path.resolve(
|
|
83
|
+
return path.resolve(distDirName(), relative.replace(/\.slim$/, ".js"))
|
|
57
84
|
}
|
|
58
85
|
|
|
59
86
|
export function resolveSlimSource(raw, fromFile) {
|
package/src/test-runner.js
CHANGED
|
@@ -3,10 +3,11 @@ import path from "node:path"
|
|
|
3
3
|
import { spawnSync } from "node:child_process"
|
|
4
4
|
import { pathToFileURL } from "node:url"
|
|
5
5
|
import { transform } from "./transform.js"
|
|
6
|
+
import { distDirName } from "./modulePaths.js"
|
|
6
7
|
|
|
7
8
|
const root = process.cwd()
|
|
8
9
|
const runtimeImport = pathToFileURL(path.resolve("src/external/defaults.js")).href
|
|
9
|
-
const outDir = path.resolve("
|
|
10
|
+
const outDir = path.resolve(distDirName(), "__slim_tests__")
|
|
10
11
|
|
|
11
12
|
function findTests(target) {
|
|
12
13
|
if (target) {
|
|
@@ -19,7 +20,7 @@ function findTests(target) {
|
|
|
19
20
|
if (!fs.existsSync(dir)) return
|
|
20
21
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
21
22
|
if (entry.isDirectory()) {
|
|
22
|
-
if (entry.name !== "node_modules" && entry.name !==
|
|
23
|
+
if (entry.name !== "node_modules" && entry.name !== distDirName() && entry.name !== ".git") {
|
|
23
24
|
walk(path.join(dir, entry.name))
|
|
24
25
|
}
|
|
25
26
|
} else if (entry.name.endsWith(".test.slim")) {
|
package/src/transform.js
CHANGED
|
@@ -7,7 +7,7 @@ import { emitJsDoc, emitDeclarations, jsdocComment } from "./jsdoc.js"
|
|
|
7
7
|
import { checkTypes, formatDiagnostics } from "./checker.js"
|
|
8
8
|
import * as t from "@babel/types"
|
|
9
9
|
import path from "node:path"
|
|
10
|
-
import { getDistPath, resolveSlimImport, resolveSlimSource } from "./modulePaths.js"
|
|
10
|
+
import { getDistPath, resolveSlimImport, resolveSlimSource, distDirName } from "./modulePaths.js"
|
|
11
11
|
import {
|
|
12
12
|
PRE_SOURCE,
|
|
13
13
|
buildPreMap,
|
|
@@ -430,7 +430,7 @@ function resolvePath(raw, fromFile) {
|
|
|
430
430
|
|
|
431
431
|
function getRuntimePath(sourceFile, entry) {
|
|
432
432
|
const distFile = getDistPath(sourceFile)
|
|
433
|
-
const runtimeAbs = path.resolve(
|
|
433
|
+
const runtimeAbs = path.resolve(distDirName(), "external", entry)
|
|
434
434
|
const rel = path.relative(path.dirname(distFile), runtimeAbs)
|
|
435
435
|
const relFixed = rel.replace(/\\/g, "/")
|
|
436
436
|
return relFixed.startsWith(".") ? relFixed : "./" + relFixed
|