Skip to content

Commit

Permalink
Add identity lookup capability to build directory class node getter m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
t-ski committed Nov 15, 2024
1 parent a854b31 commit 48fe11a
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 15 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cluster/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rapidjs.org/cluster",
"version": "0.3.1",
"version": "0.3.2",
"description": "Web server cluster (process and thread pool) utility for rJS.",
"author": "Thassilo Martin Schiepanski",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rjs-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rapidjs.org/rjs-build",
"version": "0.3.1",
"version": "0.3.2",
"description": "Core builds functionality utility for rJS.",
"author": "Thassilo Martin Schiepanski",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/rjs-build/src/Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Directory extends AFilesystemNode {

public get(relativePath: string): AFilesystemNode {
const normalizedPath: string = this.normalizePath(relativePath);
if (normalizedPath === this.normalizePath(".")) return this;
if (normalizedPath) return this.pathMap.get(normalizedPath);
}

Expand Down
11 changes: 6 additions & 5 deletions packages/rjs-build/src/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { File } from "./File";

import _config from "./_config.json";

type TBuildInterfaceCallable = (
type TPluginInterfaceCallable = (
api: {
Directory: typeof Directory;
File: typeof File;
Expand All @@ -24,7 +24,7 @@ type TBuildInterfaceCallable = (
config: TJSON,
isDev: boolean,
$PATH: string
) => (Directory | File)[];
) => (Directory | File) | (Directory | File)[];

// TODO: Access to public files (static); e.g. for sitemap plugin?
export class Plugin {
Expand Down Expand Up @@ -90,11 +90,11 @@ export class Plugin {
return buildModulePath;
}

private async fetchBuildInterface(): Promise<TBuildInterfaceCallable> {
private async fetchBuildInterface(): Promise<TPluginInterfaceCallable> {
const buildModulePath: string = this.resolveBuildModulePath();

return buildModulePath
? await new ModuleDependency<TBuildInterfaceCallable>(
? await new ModuleDependency<TPluginInterfaceCallable>(
buildModulePath
).import()
: () => [];
Expand Down Expand Up @@ -166,8 +166,9 @@ export class Plugin {
private applyResults(): Promise<(File | Directory)[]> {
return new Promise(async (resolve) => {
const applicationResults:
| (File | Directory)
| (File | Directory)[]
| Promise<(File | Directory)[]> = (
| Promise<(File | Directory) | (File | Directory)[]> = (
await this.fetchBuildInterface()
)(
{
Expand Down
56 changes: 56 additions & 0 deletions packages/rjs-build/test/unit/fs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { Directory, File } = require("../../build/api");


const directory = new Directory("virtual/", [
new File("foo.txt", "FOO"),
new File("bar.txt", "BAR"),
new File("bar.txt", "BAZ"),
new File("quux/foo.txt", "QUUX FOO"),
]);

new UnitTest("Directory nodes length")
.actual(directory.nodes.length)
.expect(4);

new UnitTest("Directory pathmap size (no path duplicates)")
.actual(directory.pathMap.size)
.expect(3);

new UnitTest("Directory .get('bar.txt')")
.actual(directory.get("bar.txt"))
.expect({
relativePath: "bar.txt",
name: "bar",
extension: "txt",
contents: "BAZ"
});

new UnitTest("Directory .get('quux/foo.txt')")
.actual(directory.get("foo.txt"))
.expect({
relativePath: "foo.txt",
name: "foo",
extension: "txt",
contents: "FOO"
});

new UnitTest("Directory .get('.') [identity]")
.actual(directory.get(".").relativePath)
.expect("virtual/");


const file = new File("virtual.js", "console.log('foo bar');");

new UnitTest("File meta")
.actual({
name: file.name,
extension: file.extension
})
.expect({
name: "virtual",
extension: "js"
});

new UnitTest("File contents")
.actual(file.contents)
.expect("console.log('foo bar');");
2 changes: 1 addition & 1 deletion packages/rjs-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rapidjs.org/rjs-handler",
"version": "0.3.1",
"version": "0.3.2",
"description": "Core HTTP-based request handler utility for rJS.",
"author": "Thassilo Martin Schiepanski",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rjs-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rapidjs.org/rjs-server",
"version": "0.3.1",
"version": "0.3.2",
"description": "Core web server utility for rJS.",
"author": "Thassilo Martin Schiepanski",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rapidjs.org/rjs",
"version": "0.3.1",
"version": "0.3.2",
"description": "rJS (pron. ‘rapidJS’) is a plugin-based build interface, and a progressive web server based on virtual build capabilities.",
"author": "Thassilo Martin Schiepanski",
"license": "Apache-2.0",
Expand Down

0 comments on commit 48fe11a

Please sign in to comment.