Skip to content

Commit

Permalink
fix: correct entry resolution in manifest.json handling based on pack…
Browse files Browse the repository at this point in the history
…age.json
  • Loading branch information
leoweyr committed Jan 27, 2025
1 parent ea61ebd commit d597bab
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ Package the Legacy Script Engine plugin:
npx lses pack
```

Deploy the Legacy Script Engine plugin package to the local Levilamina server:
Deploy the Legacy Script Engine plugin package to the local LeviLamina server:

```bash
npx lses deploy <path>
```

| Argument | Description | Type |
| -------- | --------------------------------------------- | ------ |
| `<path>` | Specific Levilamina server working directory. | String |
| `<path>` | Specific LeviLamina server working directory. | String |

## ❗ Important

The `main` configuration entry file in package.json should be relative to the project's working directory, <font color="red">not the directory of the Legacy Script Engine plugin package.</font>

For example, in a TypeScript project where index.ts is defined as the entry point in source code and the TypeScript compiler is configured via tsconfig.json to emit to the build directory named dist, you should set the `main` field in package.json to `dist/index.js`.

This ensures that the `entry` field in the manifest.json generated by `npx lses manifest` can be correctly identified and located by LeviLamina.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "legacy-script-engine-scaffold",
"version": "0.2.0",
"version": "0.2.1",
"description": "A utility for assisting in the development of Legacy Script Engine plugins.",
"bugs": "https://github.com/leoweyr/LSEScaffold/issues",
"bin": {
Expand Down
22 changes: 22 additions & 0 deletions src/nodejs/NodeJsConfigurationMainError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CliLoggableError } from "../cli/CliLoggableError";


export class NodeJsConfigurationMainError extends Error implements CliLoggableError {
private static MESSAGE: string = "The `main` configuration in package.json is incorrect.";

public constructor() {
super(NodeJsConfigurationMainError.MESSAGE);
}

public getMessage(): string {
return NodeJsConfigurationMainError.MESSAGE;
}

public getSuggestion(): Array<string> {
const suggestion: Array<string> = new Array<string>();

suggestion.push("Ensure the `main` field is set to be relative to the project's working directory.");

return suggestion;
}
}
10 changes: 8 additions & 2 deletions src/packager/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Project } from "../project/Project";
import { NodeJsConfiguration } from "../nodejs/NodeJsConfiguration";
import { ManifestFileNotFoundError } from "./ManifestFileNotFoundError";
import { ManifestConfigurationMissingError } from "./ManifestConfigurationMissingError";
import { NodeJsConfigurationMainError } from "../nodejs/NodeJsConfigurationMainError";


export class Manifest {
Expand Down Expand Up @@ -37,13 +38,18 @@ export class Manifest {
const nodeJsConfiguration: NodeJsConfiguration = this.project.getNodeJsConfiguration();
const name: string = nodeJsConfiguration.getName();
const version: string = nodeJsConfiguration.getVersion();
const entry: string = nodeJsConfiguration.getMainEntry();
const absoluteEntry: string = Path.join(this.project.getPath(), nodeJsConfiguration.getMainEntry());
const relativeEntry: string = absoluteEntry.split(`${this.project.getBuiltPath()}\\`).join("");

if (relativeEntry === absoluteEntry) {
throw new NodeJsConfigurationMainError();
}

const manifest = {
"name": name,
"version": version,
"type": "lse-nodejs",
"entry": entry,
"entry": relativeEntry,
"dependencies": [{"name": "legacy-script-engine-nodejs"}]
};

Expand Down
2 changes: 1 addition & 1 deletion src/project/TypeScriptProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class TypeScriptProject implements Project {
}

public getBuiltPath(): string {
return this.typeScriptConfiguration.getEmittedDirectory();
return Path.join(this.typeScriptConfiguration.getEmittedDirectory());
}

public getNodeJsConfiguration(): NodeJsConfiguration {
Expand Down

0 comments on commit d597bab

Please # to comment.