Skip to content

Commit

Permalink
use vite + vite-plugin-dts + @rollup/plugin-babel to build @warp-driv… (
Browse files Browse the repository at this point in the history
#9388)

* use vite + vite-plugin-dts + @rollup/plugin-babel to build @warp-drive/schema-record

* womp womp, can't bundle types due to symbols being duplicated

* Alternate: we can lie. ha
  • Loading branch information
NullVoxPopuli committed May 2, 2024
1 parent 470c78f commit feb898e
Show file tree
Hide file tree
Showing 6 changed files with 652 additions and 59 deletions.
13 changes: 8 additions & 5 deletions packages/schema-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"lint": "eslint . --quiet --cache --cache-strategy=content --report-unused-disable-directives",
"check:types": "tsc --noEmit",
"build:pkg": "rollup --config",
"build:pkg": "vite build",
"prepack": "bun run build:pkg",
"sync-hardlinks": "bun run sync-dependencies-meta-injected"
},
Expand All @@ -40,10 +40,10 @@
}
},
"peerDependencies": {
"@ember-data/request": "workspace:5.4.0-alpha.59",
"@ember-data/store": "workspace:5.4.0-alpha.59",
"@warp-drive/core-types": "workspace:0.0.0-alpha.45",
"@ember-data/tracking": "workspace:5.4.0-alpha.59",
"@ember-data/request": "workspace:5.4.0-alpha.59"
"@warp-drive/core-types": "workspace:0.0.0-alpha.45"
},
"dependenciesMeta": {
"@ember-data/request": {
Expand All @@ -69,15 +69,17 @@
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/plugin-transform-typescript": "^7.24.4",
"@babel/plugin-transform-runtime": "^7.24.3",
"@babel/plugin-transform-typescript": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@babel/preset-typescript": "^7.24.1",
"@ember-data/request": "workspace:5.4.0-alpha.59",
"@ember-data/store": "workspace:5.4.0-alpha.59",
"@ember-data/tracking": "workspace:5.4.0-alpha.59",
"@ember/string": "^3.1.1",
"@embroider/addon-dev": "^4.3.1",
"@glimmer/component": "^1.1.2",
"@rollup/plugin-babel": "^6.0.4",
"@warp-drive/build-config": "workspace:0.0.0-alpha.1",
"@warp-drive/core-types": "workspace:0.0.0-alpha.45",
"@warp-drive/internal-config": "workspace:5.4.0-alpha.59",
Expand All @@ -86,7 +88,8 @@
"rollup": "^4.14.3",
"rollup-plugin-ts": "^3.4.5",
"typescript": "^5.4.5",
"@ember/string": "^3.1.1"
"vite": "^5.2.10",
"vite-plugin-dts": "^3.9.0"
},
"ember": {
"edition": "octane"
Expand Down
34 changes: 0 additions & 34 deletions packages/schema-record/rollup.config.mjs

This file was deleted.

19 changes: 10 additions & 9 deletions packages/schema-record/src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import { assert } from '@ember/debug';
import type { Future } from '@ember-data/request';
import type Store from '@ember-data/store';
import type { NotificationType, StoreRequestInput } from '@ember-data/store';
import type {
ArrayField,
DerivedField,
FieldSchema,
GenericField,
LocalField,
ObjectField,
} from '@warp-drive/core-types/schema/fields';
import {
addToTransaction,
defineSignal,
Expand All @@ -26,6 +18,14 @@ import type { Cache } from '@warp-drive/core-types/cache';
import type { ResourceRelationship as SingleResourceRelationship } from '@warp-drive/core-types/cache/relationship';
import type { ArrayValue, ObjectValue, Value } from '@warp-drive/core-types/json/raw';
import { STRUCTURED } from '@warp-drive/core-types/request';
import type {
ArrayField,
DerivedField,
FieldSchema,
GenericField,
LocalField,
ObjectField,
} from '@warp-drive/core-types/schema/fields';
import type { Link, Links } from '@warp-drive/core-types/spec/json-api-raw';
import { RecordStore } from '@warp-drive/core-types/symbols';

Expand All @@ -34,6 +34,7 @@ import { ManagedObject } from './managed-object';
import type { SchemaService } from './schema';
import { ARRAY_SIGNAL, Checkout, Destroy, Editable, Identifier, Legacy, OBJECT_SIGNAL, Parent } from './symbols';

export { Editable, Legacy } from './symbols';
const IgnoredGlobalFields = new Set(['then', STRUCTURED]);
const RecordSymbols = new Set([Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, Signals]);

Expand Down Expand Up @@ -283,7 +284,7 @@ export class SchemaRecord {
declare [Signals]: Map<string, Signal>;
declare ___notifications: object;

constructor(store: Store, identifier: StableRecordIdentifier, Mode: { [Editable]: boolean; [Legacy]: boolean }) {
constructor(store: Store, identifier: StableRecordIdentifier, Mode: { [Editable]: boolean;[Legacy]: boolean }) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this[RecordStore] = store;
Expand Down
22 changes: 11 additions & 11 deletions packages/schema-record/src/symbols.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const SOURCE = Symbol('#source');
export const MUTATE = Symbol('#update');
export const ARRAY_SIGNAL = Symbol('#signal');
export const OBJECT_SIGNAL = Symbol('#signal');
export const NOTIFY = Symbol('#notify');
export const SOURCE = Symbol('#source') as unknown as "#source";
export const MUTATE = Symbol('#update') as unknown as "#update";
export const ARRAY_SIGNAL = Symbol('#array-signal') as unknown as "#array-signal";
export const OBJECT_SIGNAL = Symbol('#object-signal') as unknown as "object-signal";
export const NOTIFY = Symbol('#notify') as unknown as "#notify";

export const Destroy = Symbol('Destroy');
export const Identifier = Symbol('Identifier');
export const Editable = Symbol('Editable');
export const Parent = Symbol('Parent');
export const Checkout = Symbol('Checkout');
export const Legacy = Symbol('Legacy');
export const Destroy = Symbol('Destroy') as unknown as "Destroy";
export const Identifier = Symbol('Identifier') as unknown as "Identifier";
export const Editable = Symbol('Editable') as unknown as "Editable";
export const Parent = Symbol('Parent') as unknown as "Parent";
export const Checkout = Symbol('Checkout') as unknown as "Checkout";
export const Legacy = Symbol('Legacy') as unknown as "Legacy";
53 changes: 53 additions & 0 deletions packages/schema-record/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { resolve } from 'node:path';
import { babel } from '@rollup/plugin-babel';
import { external } from '@warp-drive/internal-config/rollup/external.js';
import url from 'node:url';

import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
//import { execaCommand } from 'execa';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

export default defineConfig({
esbuild: false,
build: {
outDir: 'dist',
// These targets are not "support".
// A consuming app or library should compile further if they need to support
// old browsers.
target: ['esnext', 'firefox121'],
// In case folks debug without sourcemaps
//
// TODO: do a dual build, split for development + production
// where production is optimized for CDN loading via
// https://limber.glimdown.com
minify: false,
sourcemap: true,
lib: {
// Could also be a dictionary or array of multiple entry points
entry: [
resolve(__dirname, 'src/hooks.ts'),
resolve(__dirname, 'src/record.ts'),
resolve(__dirname, 'src/schema.ts'),
],
name: '@warp-drive/schema-record',
formats: ['es'],
// the proper extensions will be added
fileName: 'index',
},
rollupOptions: {
external: external(['@embroider/macros', '@ember/debug']),
},
},
plugins: [
babel({
babelHelpers: 'inline',
extensions: ['.js', '.ts'],
}),
dts({
rollupTypes: true,
outDir: 'unstable-preview-types',
}),
],
});

0 comments on commit feb898e

Please sign in to comment.