Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed May 20, 2024
1 parent bb3ade4 commit 03b27b3
Show file tree
Hide file tree
Showing 20 changed files with 2,882 additions and 2,678 deletions.
2,184 changes: 718 additions & 1,466 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 36 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
{
"name": "unplugin-rsc",
"version": "0.0.9",
"description": "",
"imports": {
"#test-runtime": "./test-runtime.js"
},
"version": "0.0.10",
"description": "An unplugin for framework authors to implement RSC on top of.",
"type": "module",
"files": [
"dist"
"src/**/*.ts",
"src/**/*.tsx",
"dist/**/*.js",
"dist/**/*.d.ts",
"dist/**/*.*.map",
"!**/*.test.*"
],
"types": "./dist/index.d.ts",
"main": "dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"docs": "npx typedoc --out docs src/index.ts",
"test": "vitest"
"test": "node --no-warnings --enable-source-maps --loader ts-node/esm --test ./src/*.test.*",
"test:watch": "node --no-warnings --enable-source-maps --loader ts-node/esm --watch --test-only ./src/*.test.*"
},
"keywords": [
"react",
Expand All @@ -24,17 +35,24 @@
],
"author": "Jacob Ebey <jacob.ebey@live.com>",
"license": "ISC",
"devDependencies": {
"typedoc": "^0.25.7",
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vitest": "^1.1.3"
},
"dependencies": {
"@oxidation-compiler/napi": "0.2.0",
"@rollup/pluginutils": "^5.1.0",
"esbuild": "0.19.11",
"unplugin": "^1.6.0"
"@babel/core": "7.24.4",
"@babel/helper-module-imports": "7.24.3",
"@babel/helper-plugin-utils": "7.24.0",
"@babel/traverse": "7.24.1",
"@rollup/pluginutils": "5.1.0",
"unplugin": "1.10.1"
},
"devDependencies": {
"@babel/types": "7.24.0",
"@types/babel__core": "7.20.5",
"@types/babel__helper-module-imports": "7.18.3",
"@types/babel__helper-plugin-utils": "7.10.3",
"@types/babel__traverse": "7.20.5",
"@types/node": "20.12.4",
"ts-node": "10.9.2",
"typedoc": "0.25.7",
"typedoc-plugin-markdown": "3.17.1",
"typescript": "5.3.3"
}
}
126 changes: 0 additions & 126 deletions src/ast.ts

This file was deleted.

65 changes: 65 additions & 0 deletions src/client-transform.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as assert from "node:assert/strict";
import { describe, test } from "node:test";

import { parse } from "@babel/core";

import type { ClientTransformOptions } from "./client-transform.js";
import { clientTransform } from "./client-transform.js";

const js = String.raw;

function assertAST(actual: string, expected: string, log?: boolean) {
function replacer(key: string, value: unknown) {
if (key === "start" || key === "end" || key === "loc") {
return undefined;
}
return value;
}

if (log) {
console.log("---------- ACTUAL ----------");
console.log(actual);
console.log("----------------------------");
}

assert.deepEqual(
JSON.parse(JSON.stringify(parse(actual)?.program, replacer)),
JSON.parse(JSON.stringify(parse(expected)?.program, replacer))
);
}

const transformOptions: ClientTransformOptions = {
id: (filename, directive) => `${directive}:${filename}`,
importFrom: "mwap/runtime/client",
importServer: "$$server",
};

describe("use server replaces modules", () => {
test("with annotated exports", () => {
const code = js`
"use server";
import { Imported } from "third-party-imported";
export { Exported } from "third-party-exported";
export { Imported };
export const varDeclaration = "varDeclaration";
export const functionDeclaration = function functionDeclaration() {};
export function Component() {}
`;

console.log({
code: clientTransform(code, "use-server.js", transformOptions).code,
});
console.log(clientTransform(code, "use-server.js", transformOptions).code);
assertAST(
clientTransform(code, "use-server.js", transformOptions).code,
js`
import { $$server as _$$server } from "mwap/runtime/client";
export const Exported = _$$server({}, "use server:use-server.js", "Exported");
export const Imported = _$$server({}, "use server:use-server.js", "Imported");
export const varDeclaration = _$$server({}, "use server:use-server.js", "varDeclaration");
export const functionDeclaration = _$$server({}, "use server:use-server.js", "functionDeclaration");
export const Component = _$$server({}, "use server:use-server.js", "Component");
`
);
});
});
Loading

0 comments on commit 03b27b3

Please sign in to comment.