Skip to content

Commit

Permalink
Improved bundle splitting (#62)
Browse files Browse the repository at this point in the history
* Improved bundle splitting

* Added import prefix
  • Loading branch information
leo committed Jun 12, 2024
1 parent 7f4f515 commit 4026c4e
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 64 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"description": "Access the RONIN data platform via TypeScript.",
"scripts": {
"dev": "bun run build -- --watch",
"build": "tsc --build",
"build": "tsup ./src/index.ts ./src/bin/index.ts ./src/utils/index.ts --format esm",
"test": "bun test",
"lint": "bun run lint:tsc && bun run lint:eslint --",
"lint:eslint": "eslint . --ext .ts --ignore-path .gitignore",
Expand Down Expand Up @@ -90,6 +90,7 @@
"husky": "9.0.11",
"lint-staged": "15.2.5",
"prettier": "3.3.1",
"tsup": "8.1.0",
"typescript": "5.4.5"
}
}
2 changes: 1 addition & 1 deletion src/bin/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import http from 'http';
import open from 'open';
import ora from 'ora';

import { storeSession, storeTokenForBun, storeTokenForNPM } from '../utils/session';
import { storeSession, storeTokenForBun, storeTokenForNPM } from '@/src/bin/utils/session';

export default async (appToken?: string) => {
const spinner = ora('Logging in').start();
Expand Down
8 changes: 4 additions & 4 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { parseArgs } from 'util';

import { printHelp, printVersion } from '../bin/utils/info';
import initializeProject from './commands/init';
import logIn from './commands/login';
import { getSession } from './utils/session';
import initializeProject from '@/src/bin/commands/init';
import logIn from '@/src/bin/commands/login';
import { printHelp, printVersion } from '@/src/bin/utils/info';
import { getSession } from '@/src/bin/utils/session';

let values;
let positionals;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/utils/info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalkTemplate from 'chalk-template';

import { version } from '../../../package.json';
import { version } from '@/src/../package.json';

export const printVersion = () => {
console.log(version);
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSyntaxFactory } from './syntax';
import { createSyntaxFactory } from '@/src/syntax';

const { create, get, set, drop, count, batch } = createSyntaxFactory({});

export { create, get, set, drop, count, batch };
export type { RONIN } from './types/codegen';
export type { RONIN } from '@/src/types/codegen';
export default createSyntaxFactory;
12 changes: 6 additions & 6 deletions src/queries.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { processStorableObjects, uploadStorableObjects } from './storage';
import type { Query, Results } from './types/query';
import type { QueryHandlerOptions } from './types/utils';
import { runQueriesWithHooks } from './utils/data-hooks';
import { getDotNotatedPath, InvalidQueryError } from './utils/errors';
import { formatTimeFields, getProperty } from './utils/helpers';
import { processStorableObjects, uploadStorableObjects } from '@/src/storage';
import type { Query, Results } from '@/src/types/query';
import type { QueryHandlerOptions } from '@/src/types/utils';
import { runQueriesWithHooks } from '@/src/utils/data-hooks';
import { getDotNotatedPath, InvalidQueryError } from '@/src/utils/errors';
import { formatTimeFields, getProperty } from '@/src/utils/helpers';

type QueryResponse<T> = {
results: Result<T>[];
Expand Down
6 changes: 3 additions & 3 deletions src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CombinedInstructions, Query } from './types/query';
import type { StorableObject, StoredObject } from './types/storage';
import type { QueryHandlerOptions } from './types/utils';
import type { CombinedInstructions, Query } from '@/src/types/query';
import type { StorableObject, StoredObject } from '@/src/types/storage';
import type { QueryHandlerOptions } from '@/src/types/utils';

/**
* Extract `StorableObject`s from queries. These will be uploaded separately
Expand Down
6 changes: 3 additions & 3 deletions src/syntax/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { runQueriesWithStorageAndHooks } from '../queries';
import type { Query } from '../types/query';
import type { QueryHandlerOptionsFactory } from '../types/utils';
import { runQueriesWithStorageAndHooks } from '@/src/queries';
import type { Query } from '@/src/types/query';
import type { QueryHandlerOptionsFactory } from '@/src/types/utils';

/**
* Executes an array of queries and handles their results. It is used to execute
Expand Down
8 changes: 4 additions & 4 deletions src/syntax/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RONIN } from '../types/codegen';
import type { QueryHandlerOptionsFactory } from '../types/utils';
import { queriesHandler, queryHandler } from './handlers';
import { getBatchProxy, getSyntaxProxy } from './utils';
import { queriesHandler, queryHandler } from '@/src/syntax/handlers';
import { getBatchProxy, getSyntaxProxy } from '@/src/syntax/utils';
import type { RONIN } from '@/src/types/codegen';
import type { QueryHandlerOptionsFactory } from '@/src/types/utils';

/**
* Creates a syntax factory for generating and executing queries.
Expand Down
6 changes: 3 additions & 3 deletions src/syntax/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Query } from '../types/query';
import type { PromiseTuple } from '../types/utils';
import { objectFromAccessor } from '../utils/helpers';
import type { Query } from '@/src/types/query';
import type { PromiseTuple } from '@/src/types/utils';
import { objectFromAccessor } from '@/src/utils/helpers';

let inBatch = false;

Expand Down
9 changes: 0 additions & 9 deletions src/tsconfig.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/types/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StorableObjectValue, StoredObject } from './storage';
import type { ReducedFunction, ReplaceRecursively } from './utils';
import type { StorableObjectValue, StoredObject } from '@/src/types/storage';
import type { ReducedFunction, ReplaceRecursively } from '@/src/types/utils';

export namespace RONIN {
export interface RoninRecord<TId extends string = string> {
Expand Down
6 changes: 3 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type {
BeforeHookHandler,
AfterHookHandler,
DuringHookHandler,
} from '../utils/data-hooks';
} from '@/src/utils/data-hooks';

export type {
// Queries
Expand Down Expand Up @@ -56,7 +56,7 @@ export type {

// Query Instructions
WithInstruction,
} from './query';
} from '@/src/types/query';

// Storage
export type { StorableObjectValue, StoredObject } from './storage';
export type { StorableObjectValue, StoredObject } from '@/src/types/storage';
2 changes: 1 addition & 1 deletion src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Hooks } from '../utils/data-hooks';
import type { Hooks } from '@/src/utils/data-hooks';

export interface QueryHandlerOptions {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/utils/data-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type AsyncHooks from 'node:async_hooks';

import { runQueries } from '../queries';
import type { CombinedInstructions, Query, QuerySchemaType, QueryType, Results } from '../types/query';
import type { QueryHandlerOptions, RecursivePartial } from '../types/utils';
import { toDashCase } from './helpers';
import { runQueries } from '@/src/queries';
import type { CombinedInstructions, Query, QuerySchemaType, QueryType, Results } from '@/src/types/query';
import type { QueryHandlerOptions, RecursivePartial } from '@/src/types/utils';
import { toDashCase } from '@/src/utils/helpers';

const EMPTY = Symbol('empty');

Expand Down
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { runQueriesWithStorageAndHooks as runQueries } from '../queries';
import { processStorableObjects } from '../storage';
import { getBatchProxy, getSyntaxProxy } from '../syntax/utils';
import { runQueriesWithStorageAndHooks as runQueries } from '@/src/queries';
import { processStorableObjects } from '@/src/storage';
import { getBatchProxy, getSyntaxProxy } from '@/src/syntax/utils';

export { runQueries, processStorableObjects, getSyntaxProxy, getBatchProxy };
4 changes: 2 additions & 2 deletions tests/integration/edge.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, mock, spyOn, test } from 'bun:test';

import createSyntaxFactory from '../../src';
import { runQueriesWithHooks } from '../../src/utils/data-hooks';
import createSyntaxFactory from '@/src/index';
import { runQueriesWithHooks } from '@/src/utils/data-hooks';

const mockFetch = mock(async () => {
return Response.json({
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, mock, test } from 'bun:test';

import { createSyntaxFactory } from '../../src/syntax';
import type { StoredObject } from '../../src/types/storage';
import { createSyntaxFactory } from '@/src/syntax';
import type { StoredObject } from '@/src/types/storage';

let mockRequestResolvedValue: Request | undefined = undefined;
let mockResolvedRequestText: any = undefined;
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, mock, test } from 'bun:test';

import { createSyntaxFactory } from '../../src/syntax';
import type { CombinedInstructions, QueryType } from '../../src/types/query';
import { type FilteredHookQuery, runQueriesWithHooks } from '../../src/utils/data-hooks';
import { createSyntaxFactory } from '@/src/syntax';
import type { CombinedInstructions, QueryType } from '@/src/types/query';
import { type FilteredHookQuery, runQueriesWithHooks } from '@/src/utils/data-hooks';

let mockResolvedRequestText: any = undefined;

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'bun:test';

import { getDotNotatedPath } from '../../src/utils/errors';
import { getDotNotatedPath } from '@/src/utils/errors';

describe('generate dot notation', () => {
test('generate path from segments containing only strings', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, mock, spyOn, test } from 'bun:test';

import { queriesHandler } from '../../src/syntax/handlers';
import { queriesHandler } from '@/src/syntax/handlers';

let mockRequestResolvedValue: Request | undefined;

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/strings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'bun:test';

import { toDashCase } from '../../src/utils/helpers';
import { toDashCase } from '@/src/utils/helpers';

test('correctly convert strings to dash case', async () => {
expect(toDashCase('superLongSlug')).toBe('super-long-slug');
Expand Down
12 changes: 8 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"outDir": "dist",

"esModuleInterop": true,
"resolveJsonModule": true,
"baseUrl": ".",
Expand All @@ -12,7 +14,6 @@
"allowJs": true,

"moduleResolution": "node",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"pretty": true,
Expand All @@ -22,7 +23,10 @@
"noFallthroughCasesInSwitch": true,

"noUnusedLocals": true,
"noUnusedParameters": true
},
"references": [{ "path": "./src" }]
"noUnusedParameters": true,

"paths": {
"@/src/*": ["./src/*"]
}
}
}

0 comments on commit 4026c4e

Please sign in to comment.