1node --experimental-permission --allow-fs-read=* --allow-fs-write=* index.js
1deno --allow-read --allow-env --allow-net mod.ts
1name: Deno
2
3on:
4 push:
5 branches: ["main"]
6 pull_request:
7 branches: ["main"]
8
9permissions:
10 contents: read
11
12jobs:
13 test:
14 runs-on: ubuntu-latest
15
16 steps:
17 - name: Setup repo
18 uses: actions/checkout@v3
19
20 - name: Setup Deno
21 uses: denoland/setup-deno@v1
22 with:
23 deno-version: v1.x
24
25 - name: Verify formatting
26 run: deno fmt --check
27
28 - name: Run linter
29 run: deno lint
30
31 - name: Run tests
32 run: deno test --ignore=npm
33
34 - name: Run npm build
35 run: deno task npm-build
1// import from the standard library
2 import { assert } from "https://deno.land/std@0.205.0/assert/mod.ts";
3 import { parse } from "https://deno.land/std@0.205.0/flags/mod.ts";
1// import from a deno land package
2 import cliui from "https://deno.land/x/cliui@v8.0.1-deno/deno.ts";
3
4 // import from an npm package
5 import itscalledsoccer from "npm:/itscalledsoccer/";
1import { build, emptyDir } from "https://deno.land/x/dnt@0.38.1/mod.ts";
2
3const firstArg = Deno.args[0] || "v0.0.1";
4
5const version = firstArg.startsWith("v") ? firstArg.replace("v", "") : firstArg;
6
7console.log(`building version ${version}`);
8
9await emptyDir("./npm");
10
11await build({
12 entryPoints: [{
13 kind: "bin",
14 name: "lemmyscorecard",
15 path: "./mod.ts",
16 }],
17 outDir: "./npm",
18 package: {
19 name: "lemmyscorecard",
20 version,
21 description: "Gets the total post and comment karma for a Lemmy user.",
22 license: "MIT",
23 repository: {
24 type: "git",
25 url: "git+https://github.com/doug-wade/lemmy-scorecard.git",
26 },
27 bugs: {
28 url: "https://github.com/doug-wade/lemmy-scorecard/issues",
29 },
30 },
31 mappings: {
32 "npm:/lemmy-js-client/": {
33 name: "lemmy-js-client",
34 version: "^0.18.0",
35 },
36 },
37 postBuild() {
38 Deno.copyFileSync("LICENSE", "npm/LICENSE");
39 Deno.copyFileSync("README.md", "npm/README.md");
40 },
41 shims: {
42 deno: true,
43 },
44});
1import main from "./main.ts";
2 main(Deno.args);
1import "./_dnt.polyfills.js";
2 import * as dntShim from "./_dnt.shims.js";
3 import main from "./main.js";
4
5 main(dntShim.Deno.args);
1» ls node_modules/lemmyscorecard/esm/deps/deno.land/std@0.205.0/assert/
2_constants.d.ts assert_false.d.ts assert_not_equals.d.ts assert_throws.d.ts
3_constants.js assert_false.js assert_not_equals.js assert_throws.js
4_diff.d.ts assert_greater.d.ts assert_not_instance_of.d.ts assertion_error.d.ts
5_diff.js assert_greater.js assert_not_instance_of.js assertion_error.js
6_format.d.ts assert_greater_or_equal.d.ts assert_not_match.d.ts equal.d.ts
7_format.js assert_greater_or_equal.js assert_not_match.js equal.js
8assert.d.ts assert_instance_of.d.ts assert_not_strict_equals.d.ts fail.d.ts
9assert.js assert_instance_of.js assert_not_strict_equals.js fail.js
10assert_almost_equals.d.ts assert_is_error.d.ts assert_object_match.d.ts mod.d.ts
11assert_almost_equals.js assert_is_error.js assert_object_match.js mod.js
12assert_array_includes.d.ts assert_less.d.ts assert_rejects.d.ts unimplemented.d.ts
13assert_array_includes.js assert_less.js assert_rejects.js unimplemented.js
14assert_equals.d.ts assert_less_or_equal.d.ts assert_strict_equals.d.ts unreachable.d.ts
15assert_equals.js assert_less_or_equal.js assert_strict_equals.js unreachable.js
16assert_exists.d.ts assert_match.d.ts assert_string_includes.d.ts
17assert_exists.js assert_match.js assert_string_includes.js
1» deno task npm-build 1 ↵
2Task npm-build deno run --allow-env --allow-read --allow-net --allow-write --allow-run npm-build.ts
3building version 0.0.1
4[dnt] Transforming...
5[dnt] Running npm install...
6
7added 19 packages, and audited 20 packages in 2s
8
9found 0 vulnerabilities
10[dnt] Building project...
11[dnt] Type checking ESM...
12[dnt] Emitting ESM package...
13[dnt] Emitting script package...
14[dnt] Type checking script...
15[dnt] Running post build action...
16[dnt] Running tests...
17
18> lemmyscorecard@0.0.1 test
19> node test_runner.js
20
21Running tests in ./script/main.test.js...
22
23test main ...lemmy-scorecard v0.0.4
24usage: deno run lemmy-scorecard --username <my username> --instance <my instance url>
25
26 test outputs the version ... ok
27 test outputs a help message ... ok
28 test outputs an error message when called with no args ... ok
29ok
30
31Running tests in ./esm/main.test.js...
32
33test main ...lemmy-scorecard v0.0.4
34usage: deno run lemmy-scorecard --username <my username> --instance <my instance url>
35
36 test outputs the version ... ok
37 test outputs a help message ... ok
38 test outputs an error message when called with no args ... ok
39ok
40[dnt] Complete!
1» deno task npm-build
2Task npm-build deno run --allow-env --allow-read --allow-net --allow-write --allow-run npm-build.ts
3A new release of Deno is available: 1.37.2 → 1.38.0 Run `deno upgrade` to install it.
4building version 0.0.1
5[dnt] Transforming...
6[dnt] Running npm install...
7
8added 19 packages, and audited 20 packages in 2s
9
10found 0 vulnerabilities
11[dnt] Building project...
12[dnt] Type checking ESM...
13[dnt] Emitting ESM package...
14[dnt] Emitting script package...
15[dnt] Type checking script...
16[dnt] Running post build action...
17[dnt] Running tests...
18
19> lemmyscorecard@0.0.1 test
20> node test_runner.js
21
22Running tests in ./script/main.test.js...
23
24test main ...lemmy-scorecard v0.0.4
25usage: deno run lemmy-scorecard --username <my username> --instance <my instance url>
26
27 test outputs the version ...
28 AssertionError: spy not called with expected args:
29
30
31 [Diff] Actual / Expected
32
33
34 [
35 - 'lemmy-scorecard v0.0.4'
36 + 'lemmy-scorecard v0.0.5'
37 ]
38
39 at assertSpyCall (/Users/doug/code/lemmy-scorecard/npm/script/deps/deno.land/std@0.205.0/testing/mock.js:582:23)
40 at Object.<anonymous> (/Users/doug/code/lemmy-scorecard/npm/script/main.test.js:20:37)
41 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
42 at async TestSuiteInternal.runTest (/Users/doug/code/lemmy-scorecard/npm/script/deps/deno.land/std@0.205.0/testing/_test_suite.js:307:13)
43 at async TestSuiteInternal.runTest (/Users/doug/code/lemmy-scorecard/npm/script/deps/deno.land/std@0.205.0/testing/_test_suite.js:292:17)
44 at async Object.fn (/Users/doug/code/lemmy-scorecard/npm/script/deps/deno.land/std@0.205.0/testing/_test_suite.js:265:25)
45 at async Object.step (/Users/doug/code/lemmy-scorecard/npm/test_runner.js:136:21)
46 at async TestSuiteInternal.run (/Users/doug/code/lemmy-scorecard/npm/script/deps/deno.land/std@0.205.0/testing/_test_suite.js:273:13)
47 at async Object.fn (/Users/doug/code/lemmy-scorecard/npm/script/deps/deno.land/std@0.205.0/testing/_test_suite.js:130:29)
48 at async runTestDefinitions (/Users/doug/code/lemmy-scorecard/npm/test_runner.js:54:13)
49 fail
50 test outputs a help message ... ok
51 test outputs an error message when called with no args ... ok
52fail
53
54FAILURES
55
56main
57 Error: Had failing test step.
58 at runTestDefinitions (/Users/doug/code/lemmy-scorecard/npm/test_runner.js:58:26)
59 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
60 at async main (/Users/doug/code/lemmy-scorecard/npm/test_runner.js:31:9)error: Uncaught (in promise) Error: npm run test failed with exit code 1
61 throw new Error(
62 ^
63 at runCommand (https://deno.land/x/dnt@0.38.1/lib/utils.ts:56:13)
64 at eventLoopTick (ext:core/01_core.js:183:11)
65 at async build (https://deno.land/x/dnt@0.38.1/mod.ts:407:5)
66 at async file:///Users/doug/code/lemmy-scorecard/npm-build.ts:11:1
1» deno task npm-build 1 ↵
2Task npm-build deno run --allow-env --allow-read --allow-net --allow-write --allow-run npm-build.ts
3building version 0.0.1
4[dnt] Transforming...
5[dnt] Running npm install...
6
7added 19 packages, and audited 20 packages in 484ms
8
9found 0 vulnerabilities
10[dnt] Building project...
11[dnt] Type checking ESM...
12src/main.ts:71:46 - error TS2322: Type 'number' is not assignable to type 'string'.
13
1471 const scorecard = await fetchDataForUser({ username: 1, instance: 2 });
15 ~~~~~~~~
16
17 src/main.ts:27:5
18 27 username: string;
19 ~~~~~~~~
20 The expected type comes from property 'username' which is declared here on type '{ instance: string; username: string; }'
21src/main.ts:71:59 - error TS2322: Type 'number' is not assignable to type 'string'.
22
2371 const scorecard = await fetchDataForUser({ username: 1, instance: 2 });
24 ~~~~~~~~
25
26 src/main.ts:26:5
27 26 instance: string;
28 ~~~~~~~~
29 The expected type comes from property 'instance' which is declared here on type '{ instance: string; username: string; }'
30
31error: Uncaught (in promise) Error: Had 2 diagnostics.
32 throw new Error(`Had ${diagnostics.length} diagnostics.`);
33 ^
34 at getProgramAndMaybeTypeCheck (https://deno.land/x/dnt@0.38.1/mod.ts:456:17)
35 at build (https://deno.land/x/dnt@0.38.1/mod.ts:345:17)
36 at eventLoopTick (ext:core/01_core.js:183:11)
37 at async file:///Users/doug/code/lemmy-scorecard/npm-build.ts:11:1
1import main from 'https://raw.githubusercontent.com/doug-wade/lemmy-scorecard/main/main.ts';
2
3 await main(Deno.args);
1# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
4name: Node.js Package
5
6on:
7 release:
8 types: [created]
9
10jobs:
11 build:
12 runs-on: ubuntu-latest
13 steps:
14 - name: Get tag version
15 if: startsWith(github.ref, 'refs/tags/')
16 id: get_tag_version
17 run: echo "TAG_VERSION=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_ENV"
18
19 - name: Setup repo
20 uses: actions/checkout@v3
21
22 - name: Setup deno
23 uses: denoland/setup-deno@v1
24 with:
25 deno-version: v1.x
26
27 - uses: actions/setup-node@v3
28 with:
29 node-version: 20
30 registry-url: https://registry.npmjs.org/
31
32 - name: Build npm package
33 run: deno task npm-build $TAG_VERSION
34
35 - name: Publish npm package
36 working-directory: ./npm
37 run: npm publish
38 env:
39 NODE_AUTH_TOKEN: ${{secrets.npm_token}}