Skip to content

Commit

Permalink
chore(packaging): configure rollup for jitar (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
basmasking authored Apr 24, 2023
1 parent 019ec62 commit d5238cc
Show file tree
Hide file tree
Showing 53 changed files with 3,957 additions and 2,784 deletions.
6,293 changes: 3,710 additions & 2,583 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"test": "npm run test --workspace=packages/reflection --workspace=packages/serialization --workspace=packages/runtime --workspace=packages/caching --workspace=packages/server-nodejs --workspace=packages/jitar --workspace=packages/create-jitar --workspace=packages/plugin-vite --if-present"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.1",
"@rollup/plugin-typescript": "^11.1.0",
"@types/express": "^4.17.17",
"@types/express-http-proxy": "^1.6.3",
"@types/fs-extra": "^11.0.1",
Expand All @@ -46,6 +50,8 @@
"eslint": "^8.38.0",
"eslint-plugin-jitar": "0.0.1",
"lerna": "^6.6.1",
"rollup": "^3.20.2",
"rollup-plugin-dts": "^5.3.0",
"vite": "^4.2.1",
"vitest": "^0.30.0"
}
Expand Down
8 changes: 2 additions & 6 deletions packages/jitar/.npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
coverage
src
test
node_modules
.eslintignore
.eslintrc
vite.config.ts
dist/types
tsconfig.json
rollup.config.js
*.tgz
97 changes: 0 additions & 97 deletions packages/jitar/CHANGELOG.md

This file was deleted.

23 changes: 17 additions & 6 deletions packages/jitar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@
"author": "Masking Technology <[email protected]> (https://jitar.dev)",
"license": "MIT",
"type": "module",
"types": "dist/lib.d.ts",
"types": "./dist/lib.d.ts",
"sideEffects": true,
"exports": {
".": "./dist/lib.js"
".": "./dist/lib.js",
"./server": "./dist/server.js",
"./client": "./dist/client.js"
},
"scripts": {
"lint": "eslint . --ext .ts",
"build": "tsc -p tsconfig.json",
"clean": "rm -rf dist build",
"validate": "tsc -p tsconfig.json --noEmit",
"build": "npm run clean && rollup -c",
"clean": "rm -rf dist",
"release": "npm run clean && npm run build && npm publish"
},
"dependencies": {
"@jitar/runtime": "^0.4.0",
"@jitar/server-nodejs": "^0.4.0"
"@jitar/server-nodejs": "^0.4.0",
"express": "^4.18.2",
"express-http-proxy": "^1.6.3",
"fs-extra": "^11.1.1",
"glob-promise": "6.0.2",
"mime-types": "^2.1.35",
"tslog": "^4.8.2",
"yargs": "^17.7.1",
"zod": "^3.21.4"
},
"engines": {
"node": ">=18.7"
Expand All @@ -41,4 +52,4 @@
"full stack",
"web applications"
]
}
}
56 changes: 56 additions & 0 deletions packages/jitar/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import terser from '@rollup/plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
import dts from 'rollup-plugin-dts';

import { SERVER_EXTERNALS, REPLACE_VALUES } from './rollup.definitions.js';

export default [
{
external: SERVER_EXTERNALS,
input: {
server: 'src/server.ts',
client: 'src/client.ts'
},
output: {
dir: 'dist',
exports: 'named',
format: 'module',
plugins: [terser({
module: true,
mangle: false
})]
},
plugins: [
typescript(),
replace({
preventAssignment: true,
values: REPLACE_VALUES
}),
nodeResolve()
]
},
{
external: [
'./client.js',
'./server.js'
],
input: 'src/lib.ts',
output: {
file: 'dist/lib.js',
format: 'module'
},
plugins: [
typescript()
]
},
{
input: './dist/types/lib.d.ts',
output: [{ file: 'dist/lib.d.ts', format: 'module' }],
plugins: [dts({
respectExternal: true
})],
}
]
15 changes: 15 additions & 0 deletions packages/jitar/rollup.definitions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export const SERVER_EXTERNALS = [
'express',
'express-http-proxy',
'fs-extra',
'glob-promise',
'mime-types',
'tslog',
'yargs',
'zod'
];

export const REPLACE_VALUES = {
'RUNTIME_ERROR_LOCATION': '/jitar/client.js'
};
43 changes: 40 additions & 3 deletions packages/jitar/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@

export { startClient, getClient } from '@jitar/runtime';

export * from './shared.js';
export
{
HealthCheck,
Middleware,
NextHandler,
Segment,
Procedure,
Implementation,
Version,
NamedParameter,
ArrayParameter,
ObjectParameter,
BadRequest,
Forbidden,
NotFound,
NotImplemented,
PaymentRequired,
ServerError,
Teapot,
Unauthorized,
ClientNotFound,
FileNotFound,
ImplementationNotFound,
InvalidClientId,
InvalidParameterValue,
InvalidSegmentFile,
InvalidVersionNumber,
MissingParameterValue,
ModuleNotAccessible,
ModuleNotLoaded,
NoNodeAvailable,
ProcedureNotAccessible,
ProcedureNotFound,
RepositoryNotAvailable,
RuntimeNotAvailable,
SegmentNotFound,
UnknownParameter,
startClient,
getClient
} from '@jitar/runtime';
2 changes: 0 additions & 2 deletions packages/jitar/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

export { startServer, CorsMiddleware } from '@jitar/server-nodejs';

export * from './shared.js';
13 changes: 0 additions & 13 deletions packages/jitar/src/shared.ts

This file was deleted.

9 changes: 4 additions & 5 deletions packages/jitar/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"compilerOptions": {
"target": "es2022",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "es2022",
"target": "ESNext",
"module": "ESNext",
"declaration": true,
"declarationDir": "./dist/types",
"rootDir": "./src/",
"moduleResolution": "node",
"declaration": true,
"outDir": "./dist",
"removeComments": true,
"esModuleInterop": true,
Expand Down
26 changes: 18 additions & 8 deletions packages/reflection/src/models/ReflectionScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import ReflectionExport from './ReflectionExport.js';
import ReflectionGenerator from './ReflectionGenerator.js';
import ReflectionDeclaration from './ReflectionDeclaration.js';

// Required to work after minification.
const IMPORT_NAME = ReflectionImport.name;
const EXPORT_NAME = ReflectionExport.name;
const DECLARATION_NAME = ReflectionDeclaration.name;
const FUNCTION_NAME = ReflectionFunction.name;
const GETTER_NAME = ReflectionGetter.name;
const SETTER_NAME = ReflectionSetter.name;
const GENERATOR_NAME = ReflectionGenerator.name;
const CLASS_NAME = ReflectionClass.name;

export default class ReflectionScope
{
#members: ReflectionMember[];
Expand All @@ -23,21 +33,21 @@ export default class ReflectionScope

get members(): ReflectionMember[] { return this.#members; }

get imports(): ReflectionImport[] { return this.#members.filter(member => member.constructor.name === 'ReflectionImport') as ReflectionImport[]; }
get imports(): ReflectionImport[] { return this.#members.filter(member => member.constructor.name === IMPORT_NAME) as ReflectionImport[]; }

get exports(): ReflectionExport[] { return this.#members.filter(member => member.constructor.name === 'ReflectionExport') as ReflectionExport[]; }
get exports(): ReflectionExport[] { return this.#members.filter(member => member.constructor.name === EXPORT_NAME) as ReflectionExport[]; }

get declarations(): ReflectionDeclaration[] { return this.#members.filter(member => member.constructor.name === 'ReflectionDeclaration') as ReflectionDeclaration[]; }
get declarations(): ReflectionDeclaration[] { return this.#members.filter(member => member.constructor.name === DECLARATION_NAME) as ReflectionDeclaration[]; }

get functions(): ReflectionFunction[] { return this.#members.filter(member => member.constructor.name === 'ReflectionFunction') as ReflectionFunction[]; }
get functions(): ReflectionFunction[] { return this.#members.filter(member => member.constructor.name === FUNCTION_NAME) as ReflectionFunction[]; }

get getters(): ReflectionGetter[] { return this.#members.filter(member => member.constructor.name === 'ReflectionGetter') as ReflectionGetter[]; }
get getters(): ReflectionGetter[] { return this.#members.filter(member => member.constructor.name === GETTER_NAME) as ReflectionGetter[]; }

get setters(): ReflectionSetter[] { return this.#members.filter(member => member.constructor.name === 'ReflectionSetter') as ReflectionSetter[]; }
get setters(): ReflectionSetter[] { return this.#members.filter(member => member.constructor.name === SETTER_NAME) as ReflectionSetter[]; }

get generators(): ReflectionGenerator[] { return this.#members.filter(member => member.constructor.name === 'ReflectionGenerator') as ReflectionGenerator[]; }
get generators(): ReflectionGenerator[] { return this.#members.filter(member => member.constructor.name === GENERATOR_NAME) as ReflectionGenerator[]; }

get classes(): ReflectionClass[] { return this.#members.filter(member => member.constructor.name === 'ReflectionClass') as ReflectionClass[]; }
get classes(): ReflectionClass[] { return this.#members.filter(member => member.constructor.name === CLASS_NAME) as ReflectionClass[]; }

getMember(name: string): ReflectionMember | undefined
{
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/errors/ClientNotFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default class ClientNotFound extends BadRequest
get clientId() { return this.#clientId; }
}

(ClientNotFound as Loadable).source = '/jitar-runtime/errors/ClientNotFound.js';
(ClientNotFound as Loadable).source = 'RUNTIME_ERROR_LOCATION';
2 changes: 1 addition & 1 deletion packages/runtime/src/errors/FileNotFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default class FileNotFound extends NotFound
get filename() { return this.#filename; }
}

(FileNotFound as Loadable).source = '/jitar-runtime/errors/FileNotFound.js';
(FileNotFound as Loadable).source = 'RUNTIME_ERROR_LOCATION';
2 changes: 1 addition & 1 deletion packages/runtime/src/errors/ImplementationNotFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export default class ImplementationNotFound extends NotFound
get version() { return this.#version; }
}

(ImplementationNotFound as Loadable).source = '/jitar-runtime/errors/ImplementationNotFound.js';
(ImplementationNotFound as Loadable).source = 'RUNTIME_ERROR_LOCATION';
2 changes: 1 addition & 1 deletion packages/runtime/src/errors/InvalidClientId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default class InvalidClientId extends BadRequest
get clientId() { return this.#clientId; }
}

(InvalidClientId as Loadable).source = '/jitar-runtime/errors/InvalidClientId.js';
(InvalidClientId as Loadable).source = 'RUNTIME_ERROR_LOCATION';
Loading

0 comments on commit d5238cc

Please sign in to comment.