Skip to content

Commit

Permalink
fix(init.js): ensure local development is working
Browse files Browse the repository at this point in the history
The makefile and skeleton source was loading fine on final build but not on local development. This
fixes the problem by loading the file when running locally.
  • Loading branch information
anacierdem committed Feb 26, 2024
1 parent 261cd0b commit 97cb111
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {};

declare global {
var PACKAGED: boolean | undefined;
}
21 changes: 16 additions & 5 deletions modules/actions/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path="../../globals.d.ts" />

const fs = require('fs/promises');
const _fs = require('fs');
const path = require('path');

const chalk = require('chalk').stderr;
Expand Down Expand Up @@ -28,10 +31,18 @@ const {
toNativePath,
} = require('../helpers');

// @ts-ignore-next-line
const main_c = /** @type {string} */ (require('../../skeleton/src/main.c'));
// @ts-ignore-next-line
const makefile = /** @type {string} */ (require('../../skeleton/Makefile.mk'));
const main_c = globalThis.PACKAGED
? // @ts-ignore-next-line
/** @type {string} */ (require('../../skeleton/src/main.c'))
: _fs.readFileSync(path.join(__dirname, '../../skeleton/src/main.c'), 'utf8');

const makefile = globalThis.PACKAGED
? // @ts-ignore-next-line
/** @type {string} */ require('../../skeleton/Makefile.mk')
: _fs.readFileSync(
path.join(__dirname, '../../skeleton/Makefile.mk'),
'utf8'
);

/**
* @param {import('../project-info').LibdragonInfo} info
Expand Down Expand Up @@ -206,7 +217,7 @@ const autoVendor = async (info) => {
* @param {import('../project-info').LibdragonInfo} info
*/
async function copyFiles(info) {
// TODO: make use of VFS
// TODO: make use of VFS, this is far from ideal
const srcPath = path.join(info.root, 'src');

const srcStat = await fs.stat(srcPath).catch((e) => {
Expand Down
3 changes: 3 additions & 0 deletions pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ await esbuild.build({
'.c': 'text',
'.mk': 'text',
},
define: {
PACKAGED: 'sea',
},
});

await $`node --experimental-sea-config sea-config.json`;
Expand Down
4 changes: 4 additions & 0 deletions skeleton/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module './src/main.c' {
type tmp = string;
export = tmp;
}

0 comments on commit 97cb111

Please sign in to comment.