Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sec update json5 #1

Closed
wants to merge 13 commits into from
29 changes: 17 additions & 12 deletions configs/common-tsupconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

/** @type {import("tsup").Options} */
const base = {
entry: ["src/index.ts"], // will be relative to the directory that uses it
tsconfig: "./tsconfig.json", // see above
format: ["cjs"],
platform: "browser",
target: "ES2020", // TODO: this is cool, right?
replaceNodeEnv: true,
legacyOutput: true,
treeshake: "recommended"
};

const allowedModes = ["development", "production", "report"];

let mode = process.env.UIX_SDK_BUILDMODE;
Expand All @@ -39,6 +27,23 @@ if (!mode) {
process.exit(1);
}

/** @type {import("tsup").Options} */
const base = {
entry: ["src/index.ts"], // will be relative to the directory that uses it
define: {
UIX_SDK_BUILDMODE: mode,
UIX_SDK_VERSION: `"${require("../package.json").version}"`,
},
tsconfig: "./tsconfig.json", // see above
format: ["cjs"],
platform: "browser",
target: "ES2020", // TODO: this is cool, right?
replaceNodeEnv: true,
legacyOutput: true,
treeshake: "recommended",
};


const configs = {
development: {
...base,
Expand Down
4 changes: 4 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const jestConfig: JestConfigWithTsJest = {
},
],
},
globals: {
UIX_SDK_VERSION: "0.0.1-test",
UIX_SDK_BUILDMODE: "test",
},
},
],
};
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean": "del {dist,*.tsbuildinfo,docs/temp,.parcel-cache,node_modules/.cache} {packages,examples}/*/{dist,*.tsbuildinfo,node_modules/.cache,.parcel-cache,node_modules/.vite} packages/*/src/**/*.{d.ts,d.ts.map,js,js.map} && npm run -s any -- -s clean",
"declarations:build": "tsc --build",
"declarations:watch": "tsc --build tsconfig.json --watch",
"demo": "npm run build:production -- --silent --esm && npm run any example:build && node scripts/multi-server.mjs production",
"demo": "npm run build:production -- --esm && npm run any example:build && node scripts/multi-server.mjs production",
"dev": "node scripts/multi-server.mjs development",
"docs": "node scripts/generate-docs.mjs",
"docs:watch": "node scripts/generate-docs.mjs --watch",
Expand All @@ -28,7 +28,8 @@
"report:size": "node scripts/bundler.mjs report",
"test": "run-s lint test:unit test:subtests",
"test:subtests": "npm run any test",
"test:unit": "jest"
"test:unit": "jest",
"test:unit:watch": "jest --watch"
},
"devDependencies": {
"@adobe/react-spectrum": "^3.20.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/uix-core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
declare const UIX_SDK_VERSION: string;
declare const UIX_SDK_BUILDMODE: string;

/** @internal */
export const NS_ROOT = "_$pg";
export const VERSION = "0.0.1";
export const VERSION = UIX_SDK_VERSION;
export const BUILDMODE = UIX_SDK_BUILDMODE;
export const SYM_CLEANUP = Symbol(`${NS_ROOT}_cleanup`);
export const SYM_INTERNAL = Symbol(`${NS_ROOT}_internal`);
export const INIT_CALLBACK = `${NS_ROOT}_init_cb`;
193 changes: 193 additions & 0 deletions packages/uix-core/src/object-simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,199 @@ describe("function simulator exchanges functions and tickets", () => {
await expect(loneFn()).resolves.not.toThrowError();
expect(called).toBe(true);
});
it("Unwraps prototypes and exchange all functions to tickets", async () => {
class ca {
pa: number;
constructor() {
this.pa = 4;
}
getPa() {
return this.pa;
}
}
class cb {
pb: number;
ca: ca;
constructor(aa: number) {
this.pb = aa;
this.ca = new ca();
}
getNumber() {
return this.pb;
}
giftOne() {
this.pb--;
}
}
class cd extends cb {
giftOne() {
this.pb++;
}
robOne() {
this.pb--;
}
}

const toBeTicketed = new cd(5);
const ticketed = objectSimulator.simulate(toBeTicketed);
expect(ticketed).toMatchInlineSnapshot(`
{
"ca": {
"getPa": {
"_\$pg": {
"fnId": "getPa_1",
},
},
"pa": 4,
},
"getNumber": {
"_\$pg": {
"fnId": "getNumber_4",
},
},
"giftOne": {
"_\$pg": {
"fnId": "giftOne_2",
},
},
"pb": 5,
"robOne": {
"_\$pg": {
"fnId": "robOne_3",
},
},
}
`);
const unticketed = objectSimulator.materialize(ticketed);
expect(unticketed).toMatchInlineSnapshot(`
{
"ca": {
"getPa": [Function],
"pa": 4,
},
"getNumber": [Function],
"giftOne": [Function],
"pb": 5,
"robOne": [Function],
}
`);

await expect(unticketed.getNumber()).resolves.toBe(5);
await unticketed.giftOne();
await expect(unticketed.getNumber()).resolves.toBe(6);
await unticketed.robOne();
await expect(unticketed.getNumber()).resolves.toBe(5);
await expect(unticketed.ca.getPa()).resolves.toBe(4);
});

it("Ignores circular dependencies in properties, but relove them through the methods", async () => {
class ca {
pa: ca;
constructor() {
this.pa = this;
}
getPa() {
return this.pa;
}
}

const toBeTicketed = new ca();
const ticketed = objectSimulator.simulate(toBeTicketed);
expect(ticketed).toMatchInlineSnapshot(`
{
"getPa": {
"_$pg": {
"fnId": "getPa_1",
},
},
"pa": "[[Circular]]",
}
`);
const unticketed = objectSimulator.materialize(ticketed);
expect(unticketed).toMatchInlineSnapshot(`
{
"getPa": [Function],
"pa": "[[Circular]]",
}
`);
expect(
Reflect.has(
await (await (await unticketed.getPa()).getPa()).getPa(),
"getPa"
)
).toBeTruthy();
});
it("Supports classes wrapped in other classes", async () => {
class ca {
pa: number;
constructor() {
this.pa = 5;
}
getPa() {
return this.pa;
}
}
class cb {
pb: ca;
constructor() {
this.pb = new ca();
}
getCaValue() {
return this.pb.getPa();
}
}
const toBeTicketed = new cb();
const ticketed = objectSimulator.simulate(toBeTicketed);
expect(ticketed).toMatchInlineSnapshot(`
{
"getCaValue": {
"_$pg": {
"fnId": "getCaValue_2",
},
},
"pb": {
"getPa": {
"_$pg": {
"fnId": "getPa_1",
},
},
"pa": 5,
},
}
`);
const unticketed = objectSimulator.materialize(ticketed);
expect(unticketed).toMatchInlineSnapshot(`
{
"getCaValue": [Function],
"pb": {
"getPa": [Function],
"pa": 5,
},
}
`);
await expect(unticketed.pb.getPa()).resolves.toBe(5);
});

it("Supports objects with null prototypes", async () => {
const toBeTicketed = Object.create(null);
toBeTicketed["key1"] = "val1";
toBeTicketed["key2"] = "val2";
const ticketed = objectSimulator.simulate(toBeTicketed);
expect(ticketed).toMatchInlineSnapshot(`
{
"key1": "val1",
"key2": "val2",
}
`);
const unticketed = objectSimulator.materialize(ticketed);
expect(unticketed).toMatchInlineSnapshot(`
{
"key1": "val1",
"key2": "val2",
}
`);
});

it("notifies remote when FinalizationRegistry calls cleanup handler", async () => {
const willBeGCed = objectSimulator.simulate(() => {}) as DefMessage;
objectSimulator.materialize(willBeGCed);
Expand Down
15 changes: 12 additions & 3 deletions packages/uix-core/src/object-simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ObjectSimulator implements Simulator {

// #region Public Methods

makeReceiver(fn: CallableFunction) {
makeReceiver(fn: CallableFunction, parent?: Object) {
if (typeof fn !== "function") {
return NOT_TRANSFORMED;
}
Expand All @@ -95,9 +95,18 @@ export class ObjectSimulator implements Simulator {
fnTicket = {
fnId: `${fn.name || "<anonymous>"}_${++this.fnCounter}`,
};
const cleanup = receiveCalls(fn, fnTicket, new WeakRef(this.subject));
// Bind function to parent object if it exists
let boundFunction = fn;
if (parent) {
boundFunction = fn.bind(parent);
}
const cleanup = receiveCalls(
boundFunction,
fnTicket,
new WeakRef(this.subject)
);
this.subject.onOutOfScope(fnTicket, cleanup);
this.receiverTicketCache.set(fn, fnTicket);
this.receiverTicketCache.set(boundFunction, fnTicket);
}
return wrap(fnTicket);
}
Expand Down
Loading