@slim-lang/core 1.2.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slim-lang/core",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Slim extends JavaScript with runtime types, structs, operators, and components, compiling to plain Javascript",
5
5
  "main": "index.js",
6
6
  "type": "module",
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 entry = `dist/${config.main}.js`;
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 => /(^|[\\/])(node_modules|dist|\.git)([\\/]|$)/.test(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, 'dist', `${mainFile}.js`);
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' });
@@ -2,5 +2,6 @@
2
2
  "main": "path/to/your/files",
3
3
  "usePackages": true,
4
4
  "uses": "import",
5
- "packages": "packages"
5
+ "packages": "packages",
6
+ "dist": "slim-dist"
6
7
  }
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("dist/external")
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(`dist/${mainEntry}.js`)
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(`dist/${slimFileClear}.js`),
132
- path.resolve("dist/mappings.json"),
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("dist/external"))
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(`dist/${slimFileClear}.js`))
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("dist"))
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: ["dist"]
194
+ include: [distDirName()]
195
195
  }
196
196
 
197
197
  fs.writeFileSync(configPath, JSON.stringify(config, null, 4) + "\n")
@@ -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
- let dir = "packages"
15
- try {
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")
@@ -63,11 +75,12 @@ export function getDistPath(slimFile) {
63
75
  } else if (isWithin(projectRoot, abs)) {
64
76
  relative = path.relative(projectRoot, abs)
65
77
  } else {
78
+ // Drop leading "../" so out-of-project sources can't escape the dist dir.
66
79
  const stripped = path.relative(projectRoot, abs).split(path.sep).filter(seg => seg !== "..")
67
80
  relative = stripped.length ? path.join(...stripped) : path.basename(abs)
68
81
  }
69
82
 
70
- return path.resolve("dist", relative.replace(/\.slim$/, ".js"))
83
+ return path.resolve(distDirName(), relative.replace(/\.slim$/, ".js"))
71
84
  }
72
85
 
73
86
  export function resolveSlimSource(raw, fromFile) {
@@ -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("dist/__slim_tests__")
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 !== "dist" && entry.name !== ".git") {
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(`dist/external/${entry}`)
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