Skip to content
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
43 changes: 35 additions & 8 deletions header-gen/package-lock.json

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

3 changes: 1 addition & 2 deletions header-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
},
"scripts": {
"start": "ts-node --project tsconfig.cli.json src/cli.ts",
"start": "npm run build && node built/cli.js",
"test": "jest",
"prepare": "tsc",
"build": "tsc"
Expand All @@ -26,7 +26,6 @@
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
8 changes: 5 additions & 3 deletions header-gen/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { headerData } from "./inputdata";
import { generateBlob, generateCArray, generateDsHexLiteral } from "./main";
import process from 'process';
import { pathToFileURL } from 'url';
import { headerData } from "./inputdata.js";
import { generateBlob, generateCArray, generateDsHexLiteral } from "./main.js";
Comment on lines +3 to +4
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@microbit-robert this is the part I haven't had a chance to look into.
As npm run start ends up running node built/cli.js it looks like the script needs the import to include the extension.

Not sure how to get ts to convert the import statements (in which case maybe we need to reintroduce tsconfig.cli.json and npm start would then be tsc --project tsconfig.cli.json && node built/cli.js.

Copy link
Collaborator Author

@microbit-carlos microbit-carlos Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the ml extension needs the import statements in the built output as they currently are, then we'd need to make sure the packaging script still used the original tsconfig.json and excludes the cli.ts file from the package (as that'd be broken to be used with node and it doesn't do anything as an imported module).


if (require.main === module) {
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
const headerBlob = generateBlob(headerData);
console.log('Blob:', headerBlob);
console.log(`\nC code:\n${generateCArray(headerBlob)}`);
Expand Down
2 changes: 1 addition & 1 deletion header-gen/src/inputdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: MIT
*/
import { MlModelHeader } from './MlModelHeader';
import { MlModelHeader } from './MlModelHeader.js';

export const headerData: MlModelHeader = {
samples_period: 25,
Expand Down
2 changes: 1 addition & 1 deletion header-gen/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* const ml_header_action_t actions[0];
* } ml_model_header_t;
*/
import { MlModelHeader } from './MlModelHeader';
import { MlModelHeader } from './MlModelHeader.js';

const HEADER_MAGIC = 0x4D4F444C;
const CONST_SIZES = {
Expand Down
109 changes: 0 additions & 109 deletions header-gen/tsconfig.cli.json

This file was deleted.

4 changes: 2 additions & 2 deletions header-gen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "ESNext", /* Specify what module code is generated. */
"module": "NodeNext", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand Down