This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(nodejs): introduce rollup to nodejs build system for requiring …
…raw files(mustache files) (#135) * build(nodejs): introduce rollup to nodejs build system for requiring raw files(mustache files) * chore(nodejs): bump version to v0.0.2-beta.1 * build(nodejs): fix mustache codegen
- Loading branch information
Showing
15 changed files
with
328 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,4 @@ tmp/ | |
var/** | ||
!var/.gitkeep | ||
.i18n-temp.json | ||
.rollup.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const REQUIRE_PATH_TEST = /(?:\?|&)raw(?:&|$)/ | ||
|
||
function register() { | ||
const Module = require('module') | ||
const orginalLoad = Module._load | ||
const cwd = process.cwd() | ||
Module._load = function _load(request, _parent) { | ||
if (request.match(REQUIRE_PATH_TEST)) { | ||
return fs.readFileSync(path.join(path.dirname(_parent ? _parent.filename : cwd), request.split('?')[0]), 'utf8') | ||
} | ||
return orginalLoad.apply(this, arguments) | ||
} | ||
|
||
return () => { | ||
Module._load = orginalLoad | ||
} | ||
} | ||
register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "../../tools/typescript/tsconfig.cjs.json" | ||
"extends": "../../tools/typescript/tsconfig.cjs.json", | ||
"ts-node": { | ||
"require": ["tsconfig-paths/register", "./raw-loader.js"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
#!/bin/bash | ||
|
||
npm pkg set 'exports['.'].types'='./dist/index.d.ts' | ||
npm pkg set 'exports['.'].default'='./dist/index.js' | ||
npm pkg set 'main'='./dist/index.js' | ||
npm pkg set 'types'='./dist/index.d.ts' | ||
npm pkg set 'exports['.'].require'='./dist/index.cjs.js' | ||
npm pkg set 'exports['.'].import'='./dist/index.esm.js' | ||
npm pkg set 'main'='./dist/index.cjs.js' | ||
npm pkg set 'module'='./dist/index.esm.js' | ||
npm pkg set 'types'='./dist/index.d.ts' | ||
npm pkg set 'typings'='./dist/index.d.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
declare module '@roarr/middleware-serialize-error' | ||
|
||
declare module 'rollup-plugin-string' | ||
|
||
declare module '*?raw' { | ||
const content: string | ||
export default content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import typescript from '@rollup/plugin-typescript' | ||
import { raw } from './rollup/raw' | ||
|
||
const config = [ | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: './dist/index.esm.js', | ||
format: 'es', | ||
sourcemap: true | ||
}, | ||
{ | ||
file: './dist/index.cjs.js', | ||
format: 'cjs', | ||
sourcemap: true, | ||
interop: 'auto' | ||
} | ||
], | ||
plugins: [ | ||
typescript({ | ||
tsconfig: './tsconfig.build.json', | ||
sourceMap: true | ||
}), | ||
raw({ extensions: ['mustache'] }) | ||
] | ||
} | ||
] | ||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const rawRE = /(?:\?|&)raw(?:&|$)/ | ||
|
||
export function raw({ extensions }) { | ||
return { | ||
name: 'raw', | ||
|
||
resolveId(source) { | ||
if (rawRE.test(source)) { | ||
return source.split('?')[0] | ||
} | ||
return null | ||
}, | ||
|
||
load(id) { | ||
if (rawRE.test(id)) { | ||
return id.split('?')[0] | ||
} | ||
|
||
return null | ||
}, | ||
|
||
transform(code, id) { | ||
if (extensions.includes(id.split('.').pop())) { | ||
return { | ||
code: `export default ${JSON.stringify(code)};`, | ||
map: { mappings: '' } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import agentSystemMessage from '../../templates/agent/systemMessage.mustache?raw' | ||
import agentUserMessage from '../../templates/agent/userMessage.mustache?raw' | ||
import errorRetry from '../../templates/error/retry.mustache?raw' | ||
import featuresCodeInterpreterDescription from '../../templates/features/codeInterpreter/description.mustache?raw' | ||
import featuresCodeInterpreterEvalCode from '../../templates/features/codeInterpreter/evalCode.mustache?raw' | ||
import featuresSynthesizedSystemMessage from '../../templates/features/synthesized/systemMessage.mustache?raw' | ||
import featuresSynthesizedUserMessage from '../../templates/features/synthesized/userMessage.mustache?raw' | ||
import testPing from '../../templates/test/ping.mustache?raw' | ||
import { type TemplateMap } from './mustacheTypes' | ||
|
||
export const templates: Record<keyof TemplateMap, string> = { | ||
'agent/systemMessage': agentSystemMessage, | ||
'agent/userMessage': agentUserMessage, | ||
'error/retry': errorRetry, | ||
'features/codeInterpreter/description': featuresCodeInterpreterDescription, | ||
'features/codeInterpreter/evalCode': featuresCodeInterpreterEvalCode, | ||
'features/synthesized/systemMessage': featuresSynthesizedSystemMessage, | ||
'features/synthesized/userMessage': featuresSynthesizedUserMessage, | ||
'test/ping': testPing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"declaration": true, | ||
"noEmit": false, | ||
"outDir": "dist", | ||
"importHelpers": false | ||
"importHelpers": false, | ||
"incremental": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"extends": "../../tools/typescript/tsconfig.cjs.json", | ||
"include": ["./src/**/*", "./externals.d.ts"] | ||
"include": ["./src/**/*", "./templates/**/*", "./externals.d.ts"], | ||
"exclude": ["./src/**/*.test.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.