@slim-lang/core 1.2.11 → 1.2.13
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/README.md +522 -14
- package/package.json +2 -6
- package/packages/slim/server/main.slim +433 -422
- package/run-dev-slim.js +10 -5
- package/run-slim.js +10 -20
- package/src/bin/api/github_get.js +7 -12
- package/src/bin/api/github_req.js +54 -241
- package/src/bin/api/lock.js +2 -1
- package/src/bin/api/spm.js +20 -91
- package/src/bin/cli.js +73 -102
- package/src/bin/config.default.json +11 -11
- package/src/bin/helpers.js +2 -7
- package/src/bin/spm.js +3 -7
- package/src/checker.js +1705 -388
- package/src/compile.js +131 -100
- package/src/external/classErrors.js +5 -6
- package/src/external/client.js +0 -2
- package/src/external/core.js +355 -237
- package/src/external/defaults.js +12 -4
- package/src/external/dom.js +663 -0
- package/src/external/helpers.js +87 -58
- package/src/external/reactive.js +601 -0
- package/src/external/router.js +117 -0
- package/src/external/slim-globals.d.ts +43 -4
- package/src/external/typeSyntax.js +258 -0
- package/src/external/types.js +1 -1
- package/src/format.js +183 -12
- package/src/handlers/errorHandler.js +9 -36
- package/src/jsdoc.js +36 -16
- package/src/modulePaths.js +15 -5
- package/src/reactivity.js +774 -0
- package/src/repl.js +1 -1
- package/src/suggest.js +60 -0
- package/src/syntax/babel.js +46 -0
- package/src/syntax/index.js +39 -0
- package/src/syntax/lower.js +666 -0
- package/src/syntax/markup.js +195 -0
- package/src/syntax/plugin.js +903 -0
- package/src/syntax/types.js +106 -0
- package/src/test-runner.js +5 -5
- package/src/transform.js +209 -244
- package/packages/slim/helpers/string.js +0 -43
- package/packages/slim/types/hash.js +0 -11
- package/src/handlers/parser/components.js +0 -295
- package/src/handlers/parserHandler.js +0 -789
- package/src/lexer.js +0 -174
- package/src/parser.js +0 -803
- package/src/sourcemap.js +0 -0
package/src/bin/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
-
import {
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
6
5
|
import path from "node:path"
|
|
7
6
|
import fs from "node:fs"
|
|
8
7
|
import { fileURLToPath } from "node:url"
|
|
@@ -10,6 +9,7 @@ import { fileURLToPath } from "node:url"
|
|
|
10
9
|
import { log, error, parseValue } from "./helpers.js"
|
|
11
10
|
import { runTests } from "../test-runner.js"
|
|
12
11
|
import { formatFile } from "../format.js"
|
|
12
|
+
import { readJson } from "../modulePaths.js"
|
|
13
13
|
|
|
14
14
|
import pkg from "../../package.json" with { type: "json" };
|
|
15
15
|
import defaultConfig from "./config.default.json" with { type: "json" };
|
|
@@ -17,14 +17,30 @@ import defaultConfig from "./config.default.json" with { type: "json" };
|
|
|
17
17
|
const root = process.cwd()
|
|
18
18
|
|
|
19
19
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..")
|
|
20
|
-
const compileScript =
|
|
21
|
-
const runScript =
|
|
22
|
-
const devScript =
|
|
20
|
+
const compileScript = path.join(packageRoot, "src", "compile.js")
|
|
21
|
+
const runScript = path.join(packageRoot, "run-slim.js")
|
|
22
|
+
const devScript = path.join(packageRoot, "run-dev-slim.js")
|
|
23
23
|
|
|
24
24
|
const program = new Command();
|
|
25
25
|
const slimConfigPath = path.join(root, "slimconfig.json")
|
|
26
26
|
const packagePath = path.join(root, "package.json")
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
function runScripts(...scripts) {
|
|
29
|
+
for (const [script, ...args] of scripts) {
|
|
30
|
+
const { status, signal } = spawnSync(process.execPath, [script, ...args], { stdio: "inherit" })
|
|
31
|
+
if (status !== 0) {
|
|
32
|
+
process.exitCode = status ?? (signal ? 1 : 0)
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const splitList = value => value.split(/\s+/).map(item => item.trim()).filter(Boolean)
|
|
40
|
+
|
|
41
|
+
function writeSlimConfig(config) {
|
|
42
|
+
fs.writeFileSync(slimConfigPath, JSON.stringify(config, null, 4), "utf8")
|
|
43
|
+
}
|
|
28
44
|
|
|
29
45
|
function slimConfigCheck() {
|
|
30
46
|
packageCheck()
|
|
@@ -40,16 +56,15 @@ function slimConfigCheck() {
|
|
|
40
56
|
function slimConfigRead() {
|
|
41
57
|
slimConfigCheck()
|
|
42
58
|
|
|
43
|
-
return
|
|
59
|
+
return readJson(slimConfigPath);
|
|
44
60
|
}
|
|
45
|
-
// slimserver.json lives next to the entry file named by slimconfig's "main".
|
|
46
61
|
function serverConfigRead() {
|
|
47
62
|
try {
|
|
48
|
-
const config =
|
|
63
|
+
const config = readJson(slimConfigPath)
|
|
49
64
|
if (!config.main) return {}
|
|
50
65
|
|
|
51
66
|
const dir = path.dirname(path.resolve(config.main))
|
|
52
|
-
return
|
|
67
|
+
return readJson(path.join(dir, "slimserver.json"))
|
|
53
68
|
} catch {
|
|
54
69
|
return {}
|
|
55
70
|
}
|
|
@@ -72,15 +87,18 @@ program
|
|
|
72
87
|
.command("build")
|
|
73
88
|
.description("Build a Slim project")
|
|
74
89
|
.option("-S, --silent", "Build without log")
|
|
90
|
+
.option("-R, --release", "Leave runtime type checks out of the output")
|
|
75
91
|
.option("--no-check", "Build without static type checking")
|
|
92
|
+
.option("-F, --force", "Rebuild every file, ignoring the build cache")
|
|
76
93
|
.action((params) => {
|
|
77
94
|
slimConfigCheck()
|
|
78
95
|
|
|
96
|
+
if(params.release) process.env.SLIM_RELEASE = "1"
|
|
79
97
|
if(!params.check) process.env.SLIM_NO_CHECK = "1"
|
|
98
|
+
if(params.force) process.env.SLIM_FORCE = "1"
|
|
80
99
|
|
|
81
100
|
if(!params.silent) log("Building...")
|
|
82
|
-
|
|
83
|
-
if(!params.silent) log("Ready!")
|
|
101
|
+
if(runScripts([compileScript]) && !params.silent) log("Ready!")
|
|
84
102
|
});
|
|
85
103
|
|
|
86
104
|
program
|
|
@@ -97,7 +115,7 @@ program
|
|
|
97
115
|
if(params.dev) process.env.SLIM_DEV = "1"
|
|
98
116
|
if(!params.check) process.env.SLIM_NO_CHECK = "1"
|
|
99
117
|
if(!params.silent) log(params.dev ? "Building and running (dev)..." : "Building and running...")
|
|
100
|
-
|
|
118
|
+
runScripts([compileScript], [runScript])
|
|
101
119
|
});
|
|
102
120
|
|
|
103
121
|
program
|
|
@@ -107,31 +125,21 @@ program
|
|
|
107
125
|
.action((params) => {
|
|
108
126
|
const config = slimConfigRead()
|
|
109
127
|
|
|
110
|
-
if("main" in config)
|
|
111
|
-
const mainContent = fs.readFileSync(config.main + ".slim", "utf8")
|
|
128
|
+
if(!("main" in config)) return
|
|
112
129
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
let line = parseInt(params.line) - 1
|
|
116
|
-
const lines = mainContent.split("\n")
|
|
117
|
-
const lineContent = lines[line]
|
|
130
|
+
const file = config.main.endsWith(".slim") ? config.main : config.main + ".slim"
|
|
131
|
+
const mainContent = fs.readFileSync(file, "utf8")
|
|
118
132
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
else {
|
|
123
|
-
error(`Line ${line + 1} does not exist. The file contains between 1 and ${lines.length} line(-s)`)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch(e) {
|
|
127
|
-
error(e)
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
console.log(mainContent)
|
|
133
|
-
}
|
|
133
|
+
if(!params.line) {
|
|
134
|
+
console.log(mainContent)
|
|
135
|
+
return
|
|
134
136
|
}
|
|
137
|
+
|
|
138
|
+
const lines = mainContent.split(/\r?\n/)
|
|
139
|
+
const line = Number.parseInt(params.line, 10)
|
|
140
|
+
|
|
141
|
+
if(line >= 1 && line <= lines.length) console.log(lines[line - 1])
|
|
142
|
+
else error(`Line ${params.line} does not exist. The file has lines 1 to ${lines.length}`)
|
|
135
143
|
});
|
|
136
144
|
|
|
137
145
|
program
|
|
@@ -143,18 +151,17 @@ program
|
|
|
143
151
|
.action((params) => {
|
|
144
152
|
slimConfigCheck()
|
|
145
153
|
|
|
146
|
-
// Dev is on when requested on the CLI or set in slimserver.json ("dev": true).
|
|
147
154
|
const dev = Boolean(params.dev || params.hot || serverConfigRead().dev === true)
|
|
148
155
|
|
|
149
156
|
if(params.release) process.env.SLIM_RELEASE = "1"
|
|
150
157
|
|
|
151
158
|
if(dev) {
|
|
152
159
|
log("Starting Slim dev server (watch + live reload)...")
|
|
153
|
-
|
|
160
|
+
runScripts(params.hot ? [devScript, "--hot"] : [devScript])
|
|
154
161
|
}
|
|
155
162
|
else {
|
|
156
163
|
log("Starting Slim server...")
|
|
157
|
-
|
|
164
|
+
runScripts([compileScript], [runScript])
|
|
158
165
|
}
|
|
159
166
|
});
|
|
160
167
|
|
|
@@ -165,70 +172,34 @@ program
|
|
|
165
172
|
.option("-S, --set <key>=<value>", "Set key value")
|
|
166
173
|
.option("-R, --remove <key>", "Remove key")
|
|
167
174
|
.action(async (params) => {
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
let config
|
|
170
176
|
try {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if(args.length > 0) {
|
|
178
|
-
args.forEach(a => {
|
|
179
|
-
a = a.replaceAll("--", "")
|
|
180
|
-
if(a in res) {
|
|
181
|
-
console.log(res[a])
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
console.log(res)
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else if(params["set"]) {
|
|
190
|
-
const config = JSON.parse(fs.readFileSync(slimConfigPath, "utf8"));
|
|
191
|
-
const args = params["set"].split(spaceRegex).map(item => item.trim());
|
|
192
|
-
|
|
193
|
-
args.forEach(arg => {
|
|
194
|
-
if (!arg.includes("=")) return;
|
|
195
|
-
|
|
196
|
-
const [key, ...valueParts] = arg.split("=");
|
|
197
|
-
|
|
198
|
-
const value = valueParts.join("=").trim();
|
|
199
|
-
|
|
200
|
-
config[key.trim()] = parseValue(value);
|
|
201
|
-
});
|
|
177
|
+
config = slimConfigRead()
|
|
178
|
+
} catch (err) {
|
|
179
|
+
error(`slimconfig.json is not valid JSON: ${err.message}`)
|
|
180
|
+
process.exitCode = 1
|
|
181
|
+
return
|
|
182
|
+
}
|
|
202
183
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
"utf8"
|
|
207
|
-
);
|
|
184
|
+
if(params.keys) {
|
|
185
|
+
for (const key of splitList(params.keys).map(key => key.replace(/^-+/, ""))) {
|
|
186
|
+
if(key in config) console.log(config[key])
|
|
208
187
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
keys.forEach(key => {
|
|
217
|
-
delete config[key];
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
fs.writeFileSync(
|
|
221
|
-
slimConfigPath,
|
|
222
|
-
JSON.stringify(config, null, 4),
|
|
223
|
-
"utf8"
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
const config = JSON.parse(fs.readFileSync(slimConfigPath, "utf8"));
|
|
228
|
-
console.log(config)
|
|
188
|
+
}
|
|
189
|
+
else if(params.set) {
|
|
190
|
+
for (const arg of splitList(params.set)) {
|
|
191
|
+
const eq = arg.indexOf("=")
|
|
192
|
+
if(eq <= 0) continue
|
|
193
|
+
config[arg.slice(0, eq)] = parseValue(arg.slice(eq + 1))
|
|
229
194
|
}
|
|
230
|
-
|
|
231
|
-
|
|
195
|
+
writeSlimConfig(config)
|
|
196
|
+
}
|
|
197
|
+
else if(params.remove) {
|
|
198
|
+
for (const key of splitList(params.remove)) delete config[key]
|
|
199
|
+
writeSlimConfig(config)
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
console.log(config)
|
|
232
203
|
}
|
|
233
204
|
});
|
|
234
205
|
|
|
@@ -313,12 +284,12 @@ program
|
|
|
313
284
|
}
|
|
314
285
|
|
|
315
286
|
if(githubPkg.version != pkg.version) {
|
|
316
|
-
log(`
|
|
317
|
-
|
|
318
|
-
|
|
287
|
+
log(`A different Slim version is available:
|
|
288
|
+
Latest: ${githubPkg.version}
|
|
289
|
+
Yours: ${pkg.version}`)
|
|
319
290
|
}
|
|
320
291
|
else {
|
|
321
|
-
log(`You on the latest Slim version`)
|
|
292
|
+
log(`You are on the latest Slim version`)
|
|
322
293
|
}
|
|
323
294
|
}
|
|
324
295
|
catch (err) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"main": "path/to/your/files",
|
|
3
|
-
"uses": {
|
|
4
|
-
"style": "import",
|
|
5
|
-
"enabled": true
|
|
6
|
-
},
|
|
7
|
-
"names": {
|
|
8
|
-
"packages": "packages",
|
|
9
|
-
"dist": "slim-dist"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"main": "path/to/your/files",
|
|
3
|
+
"uses": {
|
|
4
|
+
"style": "import",
|
|
5
|
+
"enabled": true
|
|
6
|
+
},
|
|
7
|
+
"names": {
|
|
8
|
+
"packages": "packages",
|
|
9
|
+
"dist": "slim-dist"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/bin/helpers.js
CHANGED
|
@@ -15,13 +15,8 @@ export const rootPath = process.cwd()
|
|
|
15
15
|
export const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
16
|
|
|
17
17
|
export function parseValue(value) {
|
|
18
|
-
if(value
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
if(/^-?\d*\.?\d*$/.test(value)) {
|
|
22
|
-
return parseFloat(value)
|
|
23
|
-
}
|
|
24
|
-
|
|
18
|
+
if (value === "true" || value === "false") return value === "true"
|
|
19
|
+
if (value.trim() !== "" && Number.isFinite(Number(value))) return Number(value)
|
|
25
20
|
return value
|
|
26
21
|
}
|
|
27
22
|
|
package/src/bin/spm.js
CHANGED
|
@@ -362,7 +362,7 @@ spm
|
|
|
362
362
|
console.log("\n")
|
|
363
363
|
spmlog(formatError(`No application has been installed on the "${githubRepo}" repository\n`))
|
|
364
364
|
spmlog("Open:", formatBold.underline("https://github.com/apps/slim-package-manager/installations/new"))
|
|
365
|
-
spmlog(
|
|
365
|
+
spmlog(`Install the app, then run ${formatItalic(`${spm.name()} publish ${name}`)} again\n`)
|
|
366
366
|
|
|
367
367
|
return fail(`No application has been installed on the "${githubRepo}" repository`)
|
|
368
368
|
}
|
|
@@ -373,15 +373,11 @@ spm
|
|
|
373
373
|
contentPath: packagePath
|
|
374
374
|
})
|
|
375
375
|
|
|
376
|
-
const packageInfoReq = await getPackage({
|
|
377
|
-
name: name
|
|
378
|
-
})
|
|
379
|
-
|
|
380
376
|
if (!githubPublishReq.success) {
|
|
381
377
|
return fail("Github publish:", githubPublishReq.msg)
|
|
382
378
|
}
|
|
383
379
|
else {
|
|
384
|
-
const isPackagesExists =
|
|
380
|
+
const isPackagesExists = (await getPackage({ name })).success
|
|
385
381
|
|
|
386
382
|
if (isPackagesExists) {
|
|
387
383
|
console.log("\nPackage is already exists... updating")
|
|
@@ -408,7 +404,7 @@ spm
|
|
|
408
404
|
})
|
|
409
405
|
|
|
410
406
|
if (!updateReq.success) {
|
|
411
|
-
return fail("Failed to push the new version to GitHub")
|
|
407
|
+
return fail("Failed to push the new version to GitHub:", updateReq.msg)
|
|
412
408
|
}
|
|
413
409
|
else {
|
|
414
410
|
const publishedVer = updateReq.version
|