Skip to content

Commit

Permalink
Merge pull request #9 from sellersindustry/documentation-update
Browse files Browse the repository at this point in the history
Fixed Compile Issue
  • Loading branch information
SellersEvan authored Feb 9, 2024
2 parents 7dfc199 + 4f160ef commit d84b633
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 99 deletions.
4 changes: 2 additions & 2 deletions example-module/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SherpaSDK } from "../../lib/sdk";
import { Response } from "../../index";

export function GET() {
return SherpaSDK.Response({ "foo": 200 });
return Response({ "foo": 200 });
}
4 changes: 2 additions & 2 deletions example-module/routes/test/[test]/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SherpaSDK } from "../../../../lib/sdk";
import { Response } from "../../../../index";

export function GET(request:Request) {
return SherpaSDK.Response(request.url, { status: 200 });
return Response(request.url, { status: 200 });
}
8 changes: 5 additions & 3 deletions example-module/sherpa.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export default {
import { NewModule } from "../index";

export default NewModule({
version: 1,
name: "example",
};
name: "example-module",
});

export type SHERPA_PROPERTIES = { food: string };
2 changes: 0 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Builder } from "./lib/builder";
import { ConfigModule, ConfigServer, BundlerType } from "./lib/builder/models";
import { Environment } from "./lib/environment/index";
import { SherpaRequest } from "./lib/environment/request";
Expand All @@ -9,7 +8,6 @@ const Response = Environment.Response;

export {
BundlerType as Bundler,
Builder,
Environment,
Response,
NewModule,
Expand Down
72 changes: 0 additions & 72 deletions lib/builder/linter/config-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,72 +213,6 @@ class ConfigServerLinter {
}


























// function validateTypes(config:ConfigServer, path:string):Log[] {

// }


// let broskie:ConfigServer = {
// version:1,
// app:{
// "/test": {
// "/nice": {
// "module": "test0",
// "properties": {
// "foo": "bar",
// }
// }
// }
// }
// }
// console.log(broskie);


// function validateTypesStructure(config:ConfigServer):string {
// let modules = _getAllModulesPaths(config.app);
// let buffer = [
// ...modules.map((module, index) => {
// if (!module.hasPropertiesType) return "";
// return `import { SHERPA_PROPERTIES as MODULE_PROPERTIES_${index} } from "${module.path}";`;
// }),
// `type ConfigAppProperties = `,
// modules.map((module, index) => {
// if (!module.hasPropertiesType) {
// return `\t{ module: "${module.namespace}"; properties?:unknown; }`;
// }
// return `\t{ module: "${module.namespace}"; properties?:MODULE_PROPERTIES_${index}; }`;
// }).join(" | \n"),
// `| { [key:\`/\${string}\`]:ConfigAppProperties };`,
// `type ConfigServer = { version:number; app:ConfigAppProperties; }`
// ];
// return buffer.join("\n");
// }


function _getAllModules(app:ConfigAppProperties):string[] {
if (app["module"]) {
return [app["module"]];
Expand All @@ -292,9 +226,3 @@ function hasPropertiesType(filepath:string):boolean {
return SourceCode.GetExportedVariableNames(filepath).includes("SHERPA_PROPERTIES");
}



// function resolveModules() {

// }

12 changes: 6 additions & 6 deletions lib/builder/sourcecode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import vm from "vm";


export const DEFAULT_ESBUILD_TARGET:Partial<BuildOptions> = {
target: "es2020",
format: "esm",
format: "cjs",
target: "es2022",
platform: "node",
bundle: true,
allowOverwrite: true,
treeShaking: true,
Expand All @@ -25,16 +26,15 @@ export class SourceCode {
}


static async GetDefaultExport(file:string):Promise<unknown> {
static async GetDefaultExport(file:string):Promise<unknown> {
let result = await build({
...DEFAULT_ESBUILD_TARGET,
entryPoints: [file],
write: false,
format: "cjs",
write: false
});

let code = result.outputFiles[0].text;
let context = vm.createContext({ module: { exports: {} }});
let context = vm.createContext({ module: { exports: {} } });
vm.runInContext(code, context);
return context.module.exports.default;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/builder/sourcecode/ts-validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from "path";
import ts from "typescript";


Expand Down Expand Up @@ -26,7 +25,7 @@ function getProgram(host:ts.CompilerHost):ts.Program {


function getHost(buffer:string):ts.CompilerHost {
let defaultLibPath = path.dirname(require.resolve("typescript")) + "/lib/lib.d.ts";
let defaultLibPath = "../../../../node_modules/typescript/lib/lib.d.ts";
return {
getSourceFile: (filename) => {
if (filename === BUFFER_FILE_NAME) {
Expand Down
7 changes: 3 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sherpa": "./dist/lib/cli/index.js"
},
"scripts": {
"build": "tsc --build tsconfig.json",
"build": "tsc --build --force tsconfig.json",
"prepare": "npm run build",
"lint": "eslint . --ext .ts",
"cli": "node dist/lib/cli/index.js",
Expand Down
6 changes: 4 additions & 2 deletions sherpa.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { NewServer } from "./dist/index";

export default NewServer({
version: 1,
app: {
"/foo": {
Expand All @@ -10,4 +12,4 @@ export default {
},
}
}
}
});
9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
"target": "es2022",
"module": "commonjs",
"esModuleInterop": true,
"platform": "node",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": true,
},
"exclude": [
"node_modules",
"./dist",
"./sherpa",
"./vercel",
"./example-module"
],
"files": [
"./index.ts",
"./lib/cli/index.ts"
"./lib/cli/index.ts",
"./lib/builder/generator/handler/index.ts"
]
}

0 comments on commit d84b633

Please sign in to comment.