Skip to content

Commit

Permalink
use the aggregate rcompat/fs export to avoid shadowing globalThis.File
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Apr 12, 2024
1 parent 924b789 commit 224e014
Show file tree
Hide file tree
Showing 50 changed files with 119 additions and 113 deletions.
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/common/peers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";

const up = 4;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).peerDependencies,
...(await new FS.File(url).up(up).join(name).json()).peerDependencies,
};
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/depend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FS from "rcompat/fs";
import { packager, manifest } from "rcompat/meta";
import { File } from "rcompat/fs";
import errors from "../errors.js";

const semver_regexp = /^\^?(?<integer>\d+)\.?(?<float>.*)$/gu;
Expand All @@ -20,7 +20,7 @@ const find_dependencies = (target, current) =>
const { MissingDependencies, UpgradeDependencies } = errors;

export default async (target_dependencies, from) => {
const { dependencies } = await (await File.root()).join(manifest).json();
const { dependencies } = await (await FS.File.root()).join(manifest).json();

const versions = find_dependencies(target_dependencies, dependencies);
if (versions.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/go/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/go/load_wasm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";

const js = ".js";
const wasm = ".wasm";

export default async file => {
const path = `${file}`.slice(0, - js.length).concat(wasm);
return new Uint8Array(await File.arrayBuffer(path));
return new Uint8Array(await FS.File.arrayBuffer(path));
};
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/go/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { upperfirst } from "rcompat/string";
import { execute } from "rcompat/stdio";
import { user } from "rcompat/env";
Expand Down Expand Up @@ -76,7 +76,7 @@ const error_default = {
Float: 0,
String: "\"\"",
};
const root = new File(import.meta.url).up(1);
const root = new FS.File(import.meta.url).up(1);

const create_meta_files = async (directory, types, app) => {
const meta = {
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/python/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const make_package = pkg => `await pyodide.loadPackage("${pkg}", {
});\n`;

const js_wrapper = async (path, routes, packages) => `
import FS from "rcompat/fs";
import { make_request, make_response, wrap } from "@primate/binding/python";
import { File } from "rcompat/fs";
import { loadPyodide as load } from "pyodide";
const pyodide = await load({ indexURL: "./node_modules/pyodide" });
const file = await File.text(${JSON.stringify(path)});
const file = await FS.File.text(${JSON.stringify(path)});
${packages.map(make_package)}
pyodide.runPython(wrap(file));
export default {
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/src/bindings/python/wrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";

const wrap = await new File(import.meta.url).directory.join("wrap.py").text();
const wrap = await new FS.File(import.meta.url).directory.join("wrap.py").text();

export default code => `${wrap}\n${code}`;
6 changes: 3 additions & 3 deletions packages/binding/src/bindings/ruby/exports.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/node";

const ruby_path = (await File.root())
const ruby_path = (await FS.File.root())
.join("node_modules/@ruby/head-wasm-wasi/dist/ruby+stdlib.wasm");
const ruby_wasm = await File.arrayBuffer(ruby_path);
const ruby_wasm = await FS.File.arrayBuffer(ruby_path);
const module = await WebAssembly.compile(ruby_wasm);

export { default as make_response } from "./make_response.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/binding/src/bindings/ruby/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import o from "rcompat/object";
import { upperfirst } from "rcompat/string";
import { peers } from "../common/exports.js";
Expand All @@ -8,7 +8,7 @@ const routes_re = /def (?<route>get|post|put|delete)/gu;
const get_routes = code => [...code.matchAll(routes_re)]
.map(({ groups: { route } }) => route);

const directory = new File(import.meta.url).up(1);
const directory = new FS.File(import.meta.url).up(1);
const session_rb = await directory.join("session.rb").text();
const request = await directory.join("./request.rb").text();
const make_route = route => `async ${route.toLowerCase()}(request) {
Expand Down Expand Up @@ -61,10 +61,10 @@ end`);

return `import { make_response, module, rubyvm, helpers }
from "@primate/binding/ruby";
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
const { vm } = await rubyvm(module);
const file = await File.text(${JSON.stringify(path)});
const file = await FS.File.text(${JSON.stringify(path)});
const wrappers = ${JSON.stringify(create_ruby_wrappers(routes))};
const request = ${JSON.stringify(request
.replace("%%DISPATCH_DEFS%%", _ => type_defs)
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/src/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
4 changes: 2 additions & 2 deletions packages/create-primate/src/commands/add.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { intro } from "@clack/prompts";
import { select } from "../prompts.js";

Expand All @@ -10,7 +10,7 @@ const options = [
];

export default async () => {
intro(`Managing ${File.resolve()}`);
intro(`Managing ${FS.File.resolve()}`);

const selected = await select({
message: "Choose action",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-primate/src/commands/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FS from "rcompat/fs";
import { blue } from "rcompat/colors";
import { File } from "rcompat/fs";
import { intro, outro } from "@clack/prompts";

import run from "../run.js";
Expand Down Expand Up @@ -36,7 +36,7 @@ export default async () => {
intro("Creating a Primate app");
try {
const root = await create(await run());
const cd = File.same(root, File.resolve()) ? "" : `cd ${root} && `;
const cd = FS.File.same(root, FS.File.resolve()) ? "" : `cd ${root} && `;
outro(blue(`done, run \`${cd}npm i && npx primate\` to start`));
} catch (error) {
if (error instanceof Bailout) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-primate/src/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";

const up = 2;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).devDependencies,
...(await new FS.File(url).up(up).join(name).json()).devDependencies,
};
4 changes: 2 additions & 2 deletions packages/create-primate/src/root.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import * as prompts from "./prompts.js";

const confirm = async root => {
Expand All @@ -21,5 +21,5 @@ export default async () => {
defaultValue: ".",
});

return confirm(File.resolve(value));
return confirm(FS.File.resolve(value));
};
4 changes: 2 additions & 2 deletions packages/frontend/src/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/common/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
8 changes: 4 additions & 4 deletions packages/frontend/src/frontends/common/load.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { tryreturn } from "rcompat/async";
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import errors from "./errors.js";

const MODULE_NOT_FOUND = "ERR_MODULE_NOT_FOUND";
const in_component = (code, error_path, component_path) =>
code === MODULE_NOT_FOUND && File.same(error_path, component_path);
code === MODULE_NOT_FOUND && FS.File.same(error_path, component_path);

const MissingComponent = (name, path) => {
errors.MissingComponent.throw(name, path);
Expand All @@ -14,10 +14,10 @@ const ErrorInComponent = (name, path, error) => {
errors.ErrorInComponent.throw(name, path);
};
const get_error = (error, path) =>
in_component(error.code, new File(error.url), new File(path))
in_component(error.code, new FS.File(error.url), new FS.File(path))
? MissingComponent
: ErrorInComponent;

export default async path =>
tryreturn(_ => File.import(`${path}.js`))
tryreturn(_ => FS.File.import(`${path}.js`))
.orelse(error => get_error(error, `${path}.js`)(path.name, path, error));
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/common/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import o from "rcompat/object";
import handler from "./handler.js";
import compile from "./compile.js";
Expand All @@ -12,7 +12,7 @@ export default async ({
default_extension,
}) => {
const normalized = normalize(name);
const base = new File(import.meta.url).up(2).join(name);
const base = new FS.File(import.meta.url).up(2).join(name);
const exports_path = base.join("client", "exports.js");
const imports_path = base.join("imports.js");
const on = o.filter(peers, ([key]) => dependencies.includes(key));
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/common/peers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";

const up = 4;
const { url } = import.meta;
const name = "package.json";

export default {
...(await new File(url).up(up).join(name).json()).peerDependencies,
...(await new FS.File(url).up(up).join(name).json()).peerDependencies,
};
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/htmx/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
6 changes: 3 additions & 3 deletions packages/frontend/src/frontends/markdown/module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FS from "rcompat/fs";
import o from "rcompat/object";
import { File } from "rcompat/fs";
import { peers } from "../common/exports.js";
import depend from "../depend.js";

Expand Down Expand Up @@ -45,11 +45,11 @@ const markdown = ({
const { content, toc } = await markdown.compile(text, options);

const base = target.join(component.debase(app.path.components));
const html = new File(`${base}.html`);
const html = new FS.File(`${base}.html`);
await html.directory.create();
await html.write(content);

const json = new File(`${base}.json`);
const json = new FS.File(`${base}.json`);
await json.write(o.stringify(toc));
},
// no hydration
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/react/imports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { transform } from "rcompat/build";
import { renderToString } from "react-dom/server";
import { createElement } from "react";
Expand Down Expand Up @@ -45,7 +45,7 @@ export const publish = (app, extension) => ({
});
build.onLoad({ filter: new RegExp(`${extension}$`, "u") }, async args => {
// Load the file from the file system
const source = await File.text(args.path);
const source = await FS.File.text(args.path);

// Convert JSX syntax to JavaScript
return { contents: (await compile.client(source)).js };
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/solid/imports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { renderToString } from "solid-js/web";
import { transformAsync } from "@babel/core";
import solid from "babel-preset-solid";
Expand Down Expand Up @@ -48,7 +48,7 @@ export const publish = (app, extension) => ({
});
build.onLoad({ filter: new RegExp(`${extension}$`, "u") }, async args => {
// Load the file from the file system
const source = await File.text(args.path);
const source = await FS.File.text(args.path);

// Convert JSX syntax to JavaScript
return { contents: (await compile.client(source)).js };
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/svelte/imports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import * as compiler from "svelte/compiler";
import { expose } from "./client/exports.js";

Expand Down Expand Up @@ -43,7 +43,7 @@ export const publish = (app, extension) => ({
});
build.onLoad({ filter: new RegExp(`${extension}$`, "u") }, async args => {
// Load the file from the file system
const source = await File.text(args.path);
const source = await FS.File.text(args.path);

// Convert Svelte syntax to JavaScript
const { js, css } = compile.client(source);
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/frontends/webc/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
8 changes: 4 additions & 4 deletions packages/frontend/src/frontends/webc/imports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import errors from "./errors.js";

const script_re = /(?<=<script)>(?<code>.*?)(?=<\/script>)/gus;
Expand All @@ -9,8 +9,8 @@ export const compile = {
const [script] = await Promise.all([...text.matchAll(script_re)]
.map(({ groups: { code } }) => code));
const { name } = script.match(webc_class_name_re)?.groups ?? {};
name === undefined && errors.MissingComponentClassName.throw(component);
const tagname = new File(component).base;
name === undefined && errors.MissingComponentClassName.throw(component);
const tagname = new FS.File(component).base;

const js = `${script}
globalThis.customElements.define("${tagname}", ${name});`;
Expand All @@ -24,7 +24,7 @@ export const publish = (_, extension) => ({
setup(build) {
build.onLoad({ filter: new RegExp(`${extension}$`, "u") }, async args => {
// Load the file from the file system
const source = await File.text(args.path);
const source = await FS.File.text(args.path);

return { contents: (await compile.client(source, args.path)).js };
});
Expand Down
4 changes: 2 additions & 2 deletions packages/i18n/src/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File } from "rcompat/fs";
import FS from "rcompat/fs";
import { Logger } from "primate";

const json = await new File(import.meta.url).up(1).join("errors.json").json();
const json = await new FS.File(import.meta.url).up(1).join("errors.json").json();

export default Logger.err(json.errors, json.module);
Loading

0 comments on commit 224e014

Please sign in to comment.