@eighty4/c2 0.0.2-26 → 0.0.2-28
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/CHANGELOG.md +3 -1
- package/lib/attachments.spec.ts +14 -1
- package/lib/cli.spec.ts +20 -1
- package/lib/cli.ts +21 -11
- package/lib/expression.spec.ts +8 -0
- package/lib/expression.ts +2 -4
- package/lib_js/cli.js +17 -8
- package/lib_js/expression.js +2 -2
- package/lib_types/cli.d.ts +1 -1
- package/lib_types/cli.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/lib/attachments.spec.ts
CHANGED
|
@@ -9,7 +9,7 @@ beforeEach(async () => (tmpDir = await makeTempDir()))
|
|
|
9
9
|
|
|
10
10
|
afterEach(async () => await removeDir(tmpDir))
|
|
11
11
|
|
|
12
|
-
test('collect throws error
|
|
12
|
+
test('collect throws error for unknown filetype', async () => {
|
|
13
13
|
await makeFile('init-cloud', 'whoopie', tmpDir)
|
|
14
14
|
await expect(() => collectAttachments(tmpDir)).toThrow(
|
|
15
15
|
'init-cloud is an unsupported file type',
|
|
@@ -29,6 +29,19 @@ test('collect cloud config yml', async () => {
|
|
|
29
29
|
])
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
+
test('collect cloud config yaml', async () => {
|
|
33
|
+
await makeFile('init-cloud.yaml', '#cloud-config\nwhoopie', tmpDir)
|
|
34
|
+
expect(await collectAttachments(tmpDir)).toStrictEqual([
|
|
35
|
+
{
|
|
36
|
+
path: join(tmpDir, 'init-cloud.yaml'),
|
|
37
|
+
content: '#cloud-config\nwhoopie',
|
|
38
|
+
filename: 'init-cloud.yaml',
|
|
39
|
+
source: '#cloud-config\nwhoopie',
|
|
40
|
+
type: 'cloud-config',
|
|
41
|
+
},
|
|
42
|
+
])
|
|
43
|
+
})
|
|
44
|
+
|
|
32
45
|
test('collect throws error when yml does not have #cloud-config comment', async () => {
|
|
33
46
|
await makeFile('init-cloud.yml', 'whoopie', tmpDir)
|
|
34
47
|
await expect(() => collectAttachments(tmpDir)).toThrow(
|
package/lib/cli.spec.ts
CHANGED
|
@@ -14,6 +14,19 @@ test('parseArgs with ts entrypoint', () => {
|
|
|
14
14
|
})
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
+
test('parseArgs with executable entrypoint', () => {
|
|
18
|
+
expect(
|
|
19
|
+
parseArgs([
|
|
20
|
+
'/Users/who/.nvm/versions/node/v23.7.0/bin/node',
|
|
21
|
+
'/Users/who/.nvm/versions/node/v23.7.0/bin/c2',
|
|
22
|
+
'user_data_dir',
|
|
23
|
+
]),
|
|
24
|
+
).toStrictEqual({
|
|
25
|
+
base64: false,
|
|
26
|
+
userDataDir: 'user_data_dir',
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
17
30
|
test('parseArgs with js entrypoint', () => {
|
|
18
31
|
expect(
|
|
19
32
|
parseArgs([
|
|
@@ -27,6 +40,12 @@ test('parseArgs with js entrypoint', () => {
|
|
|
27
40
|
})
|
|
28
41
|
})
|
|
29
42
|
|
|
43
|
+
test('parseArgs with unexepected argv', () => {
|
|
44
|
+
expect(() => parseArgs(['tippity', 'doo', 'da'])).toThrow(
|
|
45
|
+
'unexpected program installation\nplease report at https://github.com/eighty4/c2/issues/new and include:\n\n[\n \"tippity\",\n \"doo\",\n \"da\"\n]',
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
|
|
30
49
|
test('parseArgs errors without USER_DATA_DIR', () => {
|
|
31
50
|
expect(() =>
|
|
32
51
|
parseArgs([
|
|
@@ -44,7 +63,7 @@ test('parseArgs errors with extra USER_DATA_DIR', () => {
|
|
|
44
63
|
'user_data_dir',
|
|
45
64
|
'some_other_arg',
|
|
46
65
|
]),
|
|
47
|
-
).toThrow(
|
|
66
|
+
).toThrow()
|
|
48
67
|
})
|
|
49
68
|
|
|
50
69
|
test('parseArgs with --base64', () => {
|
package/lib/cli.ts
CHANGED
|
@@ -7,25 +7,35 @@ export type ParsedArgs =
|
|
|
7
7
|
userDataDir: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const SCRIPT_SUFFIXES = Object.freeze([
|
|
11
|
+
'/c2',
|
|
12
|
+
'/lib_js/c2.bin.js',
|
|
13
|
+
'/lib/c2.bin.ts',
|
|
14
|
+
])
|
|
15
|
+
|
|
16
|
+
export function parseArgs(input?: Array<string>): ParsedArgs {
|
|
17
|
+
if (!input) {
|
|
18
|
+
input = process.argv
|
|
13
19
|
}
|
|
14
|
-
|
|
15
|
-
let shifted
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
) {
|
|
20
|
+
let parsing: Array<string> = [...input]
|
|
21
|
+
let shifted: string | undefined
|
|
22
|
+
let found_cli: boolean = false
|
|
23
|
+
while ((shifted = parsing.shift())) {
|
|
24
|
+
if (SCRIPT_SUFFIXES.some(suffix => shifted!.endsWith(suffix))) {
|
|
25
|
+
found_cli = true
|
|
21
26
|
break
|
|
22
27
|
}
|
|
23
28
|
}
|
|
29
|
+
if (!found_cli) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`unexpected program installation\nplease report at https://github.com/eighty4/c2/issues/new and include:\n\n${JSON.stringify(input, null, 4)}`,
|
|
32
|
+
)
|
|
33
|
+
}
|
|
24
34
|
let base64 = false
|
|
25
35
|
let httpPort: number | undefined
|
|
26
36
|
let userData: Array<string> = []
|
|
27
37
|
let expectHttpPort = false
|
|
28
|
-
for (const arg of
|
|
38
|
+
for (const arg of parsing) {
|
|
29
39
|
if (expectHttpPort) {
|
|
30
40
|
expectHttpPort = false
|
|
31
41
|
httpPort = parseInt(arg, 10)
|
package/lib/expression.spec.ts
CHANGED
|
@@ -32,6 +32,14 @@ test('env() not found', async () => {
|
|
|
32
32
|
)
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
+
test('env() name not valid', async () => {
|
|
36
|
+
;['2_NOT_VALID', 'NOT=VALID', 'NOT@VALID'].forEach(envVar =>
|
|
37
|
+
expect(() =>
|
|
38
|
+
evalTemplateExpressions(`\${{ env('${envVar}') }}`),
|
|
39
|
+
).toThrow(`env var \`${envVar}\` is not a valid name`),
|
|
40
|
+
)
|
|
41
|
+
})
|
|
42
|
+
|
|
35
43
|
test('file() not found', async () => {
|
|
36
44
|
const path = join(await makeTempDir(), 'whoopie')
|
|
37
45
|
expect(() => evalTemplateExpressions(`\${{ file('${path}') }}`)).toThrow(
|
package/lib/expression.ts
CHANGED
|
@@ -38,10 +38,8 @@ async function evaluate(expression: string): Promise<string> {
|
|
|
38
38
|
let match: RegExpMatchArray | null
|
|
39
39
|
if ((match = expression.match(/env\(\s*'(.*)'\s*\)/)) != null) {
|
|
40
40
|
const envVarKey = match[1]
|
|
41
|
-
if (
|
|
42
|
-
throw new Error(
|
|
43
|
-
`env var expression \`${envVarKey}\` is not valid syntax`,
|
|
44
|
-
)
|
|
41
|
+
if (!/^[A-Z_][A-Z_\d]+$/.test(envVarKey)) {
|
|
42
|
+
throw new Error(`env var \`${envVarKey}\` is not a valid name`)
|
|
45
43
|
}
|
|
46
44
|
const envVarValue = process.env[envVarKey]
|
|
47
45
|
if (!envVarValue) {
|
package/lib_js/cli.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const SCRIPT_SUFFIXES = Object.freeze([
|
|
2
|
+
'/c2',
|
|
3
|
+
'/lib_js/c2.bin.js',
|
|
4
|
+
'/lib/c2.bin.ts',
|
|
5
|
+
]);
|
|
6
|
+
export function parseArgs(input) {
|
|
7
|
+
if (!input) {
|
|
8
|
+
input = process.argv;
|
|
4
9
|
}
|
|
5
|
-
|
|
10
|
+
let parsing = [...input];
|
|
6
11
|
let shifted;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
let found_cli = false;
|
|
13
|
+
while ((shifted = parsing.shift())) {
|
|
14
|
+
if (SCRIPT_SUFFIXES.some(suffix => shifted.endsWith(suffix))) {
|
|
15
|
+
found_cli = true;
|
|
10
16
|
break;
|
|
11
17
|
}
|
|
12
18
|
}
|
|
19
|
+
if (!found_cli) {
|
|
20
|
+
throw new Error(`unexpected program installation\nplease report at https://github.com/eighty4/c2/issues/new and include:\n\n${JSON.stringify(input, null, 4)}`);
|
|
21
|
+
}
|
|
13
22
|
let base64 = false;
|
|
14
23
|
let httpPort;
|
|
15
24
|
let userData = [];
|
|
16
25
|
let expectHttpPort = false;
|
|
17
|
-
for (const arg of
|
|
26
|
+
for (const arg of parsing) {
|
|
18
27
|
if (expectHttpPort) {
|
|
19
28
|
expectHttpPort = false;
|
|
20
29
|
httpPort = parseInt(arg, 10);
|
package/lib_js/expression.js
CHANGED
|
@@ -24,8 +24,8 @@ async function evaluate(expression) {
|
|
|
24
24
|
let match;
|
|
25
25
|
if ((match = expression.match(/env\(\s*'(.*)'\s*\)/)) != null) {
|
|
26
26
|
const envVarKey = match[1];
|
|
27
|
-
if (
|
|
28
|
-
throw new Error(`env var
|
|
27
|
+
if (!/^[A-Z_][A-Z_\d]+$/.test(envVarKey)) {
|
|
28
|
+
throw new Error(`env var \`${envVarKey}\` is not a valid name`);
|
|
29
29
|
}
|
|
30
30
|
const envVarValue = process.env[envVarKey];
|
|
31
31
|
if (!envVarValue) {
|
package/lib_types/cli.d.ts
CHANGED
package/lib_types/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../lib/cli.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IACI,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACtB,CAAA;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../lib/cli.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IACI,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACtB,CAAA;AAQP,wBAAgB,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,UAAU,CAqD3D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eighty4/c2",
|
|
3
|
-
"version": "0.0.2-
|
|
3
|
+
"version": "0.0.2-28",
|
|
4
4
|
"author": "Adam McKee <adam.be.g84d@gmail.com>",
|
|
5
5
|
"repository": "https://github.com/eighty4/c2",
|
|
6
6
|
"homepage": "https://github.com/eighty4/c2",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"bun": "./
|
|
28
|
-
"node": "./
|
|
27
|
+
"bun": "./lib/c2.api.ts",
|
|
28
|
+
"node": "./lib_js/c2.api.js"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"imports": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"types": "./lib_types",
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "tsc
|
|
39
|
+
"build": "tsc",
|
|
40
40
|
"fmt": "prettier --write .",
|
|
41
41
|
"fmtcheck": "prettier --check .",
|
|
42
42
|
"typecheck": "tsc --noEmit"
|