Skip to content

Commit a3027dd

Browse files
mythmonmbostock
andauthored
windows support (#944)
* disable autocrlf * test on windows * cross-spawn * rimraf * use cross-env to run mocha * fix tests with posix paths * one less op * mostly posix Co-authored-by: Mike Bostock <[email protected]> * fix data loader and config tests * more tests * all tests passing * tweak gitattributes * test fixes * .gitattributes, take 3? * fix empty inversion * fix isEmpty logic, again * Update src/files.ts * add rimraf to templates --------- Co-authored-by: Mike Bostock <[email protected]> Co-authored-by: Mike Bostock <[email protected]>
1 parent fcbca53 commit a3027dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+437
-98
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ask git to not change line endings (to preserve content hashes).
2+
* -text

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ jobs:
1111
strategy:
1212
matrix:
1313
version: [20, 21]
14-
runs-on: ubuntu-latest
14+
os: [ubuntu-latest, windows-latest]
15+
fail-fast: false
16+
runs-on: ${{ matrix.os }}
1517
steps:
1618
- uses: actions/checkout@v4
1719
- uses: actions/setup-node@v4
@@ -28,7 +30,7 @@ jobs:
2830
- uses: actions/upload-artifact@v3
2931
if: failure()
3032
with:
31-
name: test-output-changes
33+
name: test-output-changes-${{ matrix.os }}-${{ matrix.version }}
3234
path: |
3335
test/output/*-changed.*
3436
test/output/build/*-changed/

bin/observable-init.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
#!/usr/bin/env -S node --no-warnings=ExperimentalWarning
1+
#!/usr/bin/env node
2+
import {fileURLToPath} from "node:url";
3+
import crossSpawn from "cross-spawn";
24

3-
await import("tsx/esm");
4-
await import("./observable.ts");
5+
crossSpawn.sync(
6+
"node",
7+
[
8+
"--no-warnings=ExperimentalWarning",
9+
"--import",
10+
"tsx/esm",
11+
fileURLToPath(import.meta.resolve("./observable.ts")),
12+
...process.argv.slice(2)
13+
],
14+
{stdio: "inherit"}
15+
);

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
"observable": "bin/observable-init.js"
2323
},
2424
"scripts": {
25-
"dev": "rm -f docs/themes.md docs/theme/*.md && (tsx watch docs/theme/generate-themes.ts & tsx watch --no-warnings=ExperimentalWarning ./bin/observable.ts preview --no-open)",
26-
"build": "yarn rebuild-themes && rm -rf dist && tsx --no-warnings=ExperimentalWarning ./bin/observable.ts build",
25+
"dev": "rimraf --glob docs/themes.md docs/theme/*.md && (tsx watch docs/theme/generate-themes.ts & tsx watch --no-warnings=ExperimentalWarning ./bin/observable.ts preview --no-open)",
26+
"build": "yarn rebuild-themes && rimraf dist && tsx --no-warnings=ExperimentalWarning ./bin/observable.ts build",
2727
"deploy": "yarn rebuild-themes && tsx --no-warnings=ExperimentalWarning ./bin/observable.ts deploy",
28-
"rebuild-themes": "rm -f docs/themes.md docs/theme/*.md && tsx docs/theme/generate-themes.ts",
28+
"rebuild-themes": "rimraf --glob docs/themes.md docs/theme/*.md && tsx docs/theme/generate-themes.ts",
2929
"test": "yarn test:mocha && yarn test:tsc && yarn test:lint && yarn test:prettier",
3030
"test:coverage": "c8 yarn test:mocha",
31-
"test:mocha": "rm -rf test/.observablehq/cache test/input/build/*/.observablehq/cache && OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles tsx --no-warnings=ExperimentalWarning ./node_modules/.bin/mocha 'test/**/*-test.*'",
31+
"test:mocha": "rimraf --glob test/.observablehq/cache test/input/build/*/.observablehq/cache && cross-env OBSERVABLE_TELEMETRY_DISABLE=1 TZ=America/Los_Angeles tsx --no-warnings=ExperimentalWarning ./node_modules/mocha/bin/mocha.js 'test/**/*-test.*'",
3232
"test:lint": "eslint src test --max-warnings=0",
3333
"test:prettier": "prettier --check src test",
3434
"test:tsc": "tsc --noEmit",
@@ -53,6 +53,8 @@
5353
"acorn": "^8.11.2",
5454
"acorn-walk": "^8.3.0",
5555
"ci-info": "^4.0.0",
56+
"cross-env": "^7.0.3",
57+
"cross-spawn": "^7.0.3",
5658
"esbuild": "^0.19.8",
5759
"fast-array-diff": "^1.1.0",
5860
"gray-matter": "^4.0.3",
@@ -78,6 +80,7 @@
7880
"ws": "^8.14.2"
7981
},
8082
"devDependencies": {
83+
"@types/cross-spawn": "^6.0.6",
8184
"@types/d3-array": "^3.2.1",
8285
"@types/he": "^1.2.3",
8386
"@types/jsdom": "^21.1.6",
@@ -103,6 +106,7 @@
103106
"fast-deep-equal": "^3.1.3",
104107
"mocha": "^10.2.0",
105108
"prettier": "^3.0.3 <3.1",
109+
"rimraf": "^5.0.5",
106110
"typescript": "^5.2.2",
107111
"undici": "^5.27.2"
108112
},

src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {createHash} from "node:crypto";
22
import {existsSync} from "node:fs";
33
import {access, constants, copyFile, readFile, writeFile} from "node:fs/promises";
4-
import {basename, dirname, extname, join} from "node:path";
4+
import {basename, dirname, extname, join} from "node:path/posix";
55
import type {Config} from "./config.js";
66
import {Loader} from "./dataloader.js";
77
import {CliError, isEnoent} from "./error.js";

src/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import {basename, dirname, join} from "node:path";
1+
import op from "node:path";
2+
import {basename, dirname, join} from "node:path/posix";
3+
import {cwd} from "node:process";
4+
import {pathToFileURL} from "node:url";
25
import {visitMarkdownFiles} from "./files.js";
36
import {formatIsoDate, formatLocaleDate} from "./format.js";
47
import {parseMarkdown} from "./markdown.js";
@@ -51,7 +54,7 @@ export interface Config {
5154

5255
export async function readConfig(configPath?: string, root?: string): Promise<Config> {
5356
if (configPath === undefined) return readDefaultConfig(root);
54-
const importPath = join(process.cwd(), root ?? ".", configPath);
57+
const importPath = pathToFileURL(op.join(cwd(), root ?? ".", configPath)).toString();
5558
return normalizeConfig((await import(importPath)).default, root);
5659
}
5760

src/convert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {existsSync} from "node:fs";
22
import {utimes, writeFile} from "node:fs/promises";
3-
import {join} from "node:path";
3+
import {join} from "node:path/posix";
44
import * as clack from "@clack/prompts";
55
import wrapAnsi from "wrap-ansi";
66
import type {ClackEffects} from "./clack.js";

src/create.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {exec} from "node:child_process";
22
import {accessSync, existsSync, readdirSync, statSync} from "node:fs";
33
import {constants, copyFile, mkdir, readFile, readdir, stat, writeFile} from "node:fs/promises";
4-
import {basename, dirname, join, normalize, resolve} from "node:path";
4+
import op from "node:path";
5+
import {basename, dirname, join, normalize} from "node:path/posix";
56
import {setTimeout as sleep} from "node:timers/promises";
67
import {fileURLToPath} from "node:url";
78
import {promisify} from "node:util";
@@ -91,7 +92,7 @@ export async function create(options = {}, effects: CreateEffects = defaultEffec
9192
const s = clack.spinner();
9293
s.start("Copying template files");
9394
const template = includeSampleFiles ? "default" : "empty";
94-
const templateDir = resolve(fileURLToPath(import.meta.url), "..", "..", "templates", template);
95+
const templateDir = op.resolve(fileURLToPath(import.meta.url), "..", "..", "templates", template);
9596
const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager ?? "npm"} run`;
9697
const installCommand = `${packageManager ?? "npm"} install`;
9798
await effects.sleep(1000);

src/dataloader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {spawn} from "node:child_process";
21
import {type WriteStream, createReadStream, existsSync, statSync} from "node:fs";
32
import {mkdir, open, readFile, rename, unlink} from "node:fs/promises";
4-
import {dirname, extname, join} from "node:path";
3+
import {dirname, extname, join} from "node:path/posix";
54
import {createGunzip} from "node:zlib";
5+
import {spawn} from "cross-spawn";
66
import JSZip from "jszip";
77
import {extract} from "tar-stream";
88
import {maybeStat, prepareOutput} from "./files.js";

src/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {join} from "node:path";
1+
import {join} from "node:path/posix";
22
import * as clack from "@clack/prompts";
33
import wrapAnsi from "wrap-ansi";
44
import type {BuildEffects} from "./build.js";

0 commit comments

Comments
 (0)