Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Feb 14, 2024
1 parent 74e11bc commit b305de9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@dfinity/principal": "^0.20.2",
"@junobuild/admin": "^0.0.45",
"@junobuild/core-peer": "^0.0.10",
"@junobuild/types": "file:../juno-js/packages/types",
"@junobuild/utils": "^0.0.18",
"conf": "^12.0.0",
"file-type": "^19.0.0",
Expand Down
37 changes: 34 additions & 3 deletions src/configs/juno.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {existsSync} from 'node:fs';
import {existsSync, readFileSync} from 'node:fs';

Check failure on line 1 in src/configs/juno.config.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,·readFileSync`

Check warning on line 1 in src/configs/juno.config.ts

View workflow job for this annotation

GitHub Actions / lint

'readFileSync' is defined but never used. Allowed unused vars must match /^_/u
import {access, readFile, writeFile} from 'node:fs/promises';
import {join} from 'node:path';
import {JUNO_CONFIG_FILENAME} from '../constants/constants';
Expand Down Expand Up @@ -77,23 +77,54 @@ const junoConfigFile = (): {configPath: string; configType: 'ts' | 'js' | 'json'
};
}

const junoCjs = join(process.cwd(), `${JUNO_CONFIG_FILENAME}.cjs`);

if (existsSync(junoCjs)) {
return {
configPath: junoCjs,
configType: 'js'
};
}

return {
configPath: join(process.cwd(), `${JUNO_CONFIG_FILENAME}.json`),
configType: 'json'
};
};

// TODO
const writeJunoConfig = async (config: JunoConfig): Promise<void> => {
await writeFile(JUNO_CONFIG_FILENAME, JSON.stringify(config, null, 2), 'utf-8');
};

// TODO: replace
export function defineConfig(config: JunoConfig): JunoConfig;
export function defineConfig(config: JunoConfig): JunoConfig {
return config;
}

const readJunoConfig = async (): Promise<JunoConfig> => {
const {configPath, configType} = junoConfigFile();

switch (configType) {
case 'ts': {

Check failure on line 110 in src/configs/juno.config.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
const modTs = nodeRequire<JunoConfig>(configPath);
return modTs.default;

// const module = await import(`data:text/javascript;base64,${Buffer.from(readFileSync(configPath).toString()).toString(`base64`)}`);
// console.log('MODUE', module)
//
// console.log(readFileSync(configPath).toString());
// const tmp = `data:text/javascript,${readFileSync(configPath).toString()}`;
// const result = await import(tmp);
//
//
// console.log('instance', result);

const userConfig = nodeRequire<JunoConfig | typeof defineConfig>(configPath).default;
const config = typeof userConfig === 'function' ? userConfig : userConfig;

console.log('Config', config);

return config;

Check failure on line 127 in src/configs/juno.config.ts

View workflow job for this annotation

GitHub Actions / build

Type 'JunoConfig | ((config: JunoConfig) => JunoConfig)' is not assignable to type 'JunoConfig'.
}
case 'js': {
const modJs = await import(configPath);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/node.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {transformFileSync} from '@babel/core';
import * as mod from '@babel/plugin-transform-modules-commonjs';
import * as ts from '@babel/preset-typescript';
import * as tst from "@junobuild/types";

Check failure on line 4 in src/utils/node.utils.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `*·as·tst·from·"@junobuild/types";⏎import·`

Check warning on line 4 in src/utils/node.utils.ts

View workflow job for this annotation

GitHub Actions / lint

'tst' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 4 in src/utils/node.utils.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@junobuild/types' or its corresponding type declarations.
import {readFileSync} from 'node:fs';

/**
Expand All @@ -25,6 +26,9 @@ export const nodeRequire = <T>(id: string): {default: T} => {
presets: [ts.default],
plugins: [mod.default]
}).code;

console.log(sourceText)

Check failure on line 30 in src/utils/node.utils.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎` with `;`

} else {
// quick hack to turn a modern es module
// into and old school commonjs module
Expand Down

0 comments on commit b305de9

Please sign in to comment.