Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mjs. #154

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

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

17 changes: 11 additions & 6 deletions src/NodeJS/Javascript/Servers/OutOfProcess/Http/Http11Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ function serverOnRequestListener(req: http.IncomingMessage, res: http.ServerResp
}
} else if (invocationRequest.moduleSourceType === ModuleSourceType.File) {
const resolvedPath = path.resolve(projectDir, invocationRequest.moduleSource);
exports = __non_webpack_require__(resolvedPath);
if (resolvedPath.endsWith('.mjs')) {
exports = await import(/* webpackIgnore: true */ 'file:///' + resolvedPath.replaceAll('\\', '/'));
} else {
exports = __non_webpack_require__(resolvedPath);
}
} else {
respondWithError(res, `Invalid module source type: ${invocationRequest.moduleSourceType}.`);
return;
Expand All @@ -140,12 +144,13 @@ function serverOnRequestListener(req: http.IncomingMessage, res: http.ServerResp
respondWithError(res, `The export named ${invocationRequest.exportName} from module ${getTempIdentifier(invocationRequest)} is not a function.`);
return;
}
} else {
if (!(typeof exports === 'function')) {
respondWithError(res, `The module ${getTempIdentifier(invocationRequest)} does not export a function.`);
return;
}
} else if (typeof exports === 'function') {
functionToInvoke = exports;
} else if (typeof exports.default === 'function') { // .mjs default export
functionToInvoke = exports.default;
} else {
respondWithError(res, `The module ${getTempIdentifier(invocationRequest)} does not export a function.`);
return;
}

let callbackCalled = false;
Expand Down
17 changes: 11 additions & 6 deletions src/NodeJS/Javascript/Servers/OutOfProcess/Http/Http20Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ function serverOnRequestListener(req: http2.Http2ServerRequest, res: http2.Http2
}
} else if (invocationRequest.moduleSourceType === ModuleSourceType.File) {
const resolvedPath = path.resolve(projectDir, invocationRequest.moduleSource);
exports = __non_webpack_require__(resolvedPath);
if (resolvedPath.endsWith('.mjs')) {
exports = await import(/* webpackIgnore: true */ 'file:///' + resolvedPath.replaceAll('\\', '/'));
} else {
exports = __non_webpack_require__(resolvedPath);
}
} else {
respondWithError(res, `Invalid module source type: ${invocationRequest.moduleSourceType}.`);
return;
Expand All @@ -126,12 +130,13 @@ function serverOnRequestListener(req: http2.Http2ServerRequest, res: http2.Http2
respondWithError(res, `The export named ${invocationRequest.exportName} from module ${getTempIdentifier(invocationRequest)} is not a function.`);
return;
}
} else {
if (!(typeof exports === 'function')) {
respondWithError(res, `The module ${getTempIdentifier(invocationRequest)} does not export a function.`);
return;
}
} else if (typeof exports === 'function') {
functionToInvoke = exports;
} else if (typeof exports.default === 'function') { // .mjs default export
functionToInvoke = exports.default;
} else {
respondWithError(res, `The module ${getTempIdentifier(invocationRequest)} does not export a function.`);
return;
}

let callbackCalled = false;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeJS/Javascript/Servers/OutOfProcess/Http/Shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path = require("path");
const path = require("path");
import * as http from 'http';
import * as http2 from 'http2';
import InvocationRequest from "../../../InvocationData/InvocationRequest";
Expand Down
5 changes: 3 additions & 2 deletions src/NodeJS/Javascript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"target": "es2022",
"module": "es2022",
"esModuleInterop": true,
"moduleResolution": "node",
"typeRoots": [ "node_modules/@types" ],
"types": [ "node" ]
Expand Down
2 changes: 1 addition & 1 deletion src/NodeJS/Jering.Javascript.NodeJS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<ItemGroup>
<ProjectReference Include="..\..\generators\Jering.Javascript.NodeJS.CodeGenerators\Jering.Javascript.NodeJS.CodeGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<!-- Documentation only needs to be generated once, for the latest framework -->
<ProjectReference Condition=" '$(TargetFramework)' == 'net5.0' " Include="..\..\generators\Jering.Javascript.NodeJS.DocumentationGenerators\Jering.Javascript.NodeJS.DocumentationGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Condition=" '$(TargetFramework)' == 'net7.0' " Include="..\..\generators\Jering.Javascript.NodeJS.DocumentationGenerators\Jering.Javascript.NodeJS.DocumentationGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading