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

Crates folder #20

Merged
merged 9 commits into from
May 17, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/pr/test-integration.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export MACH_SKIP_POST_INSTALL="true"

profile=release os=linux arch=amd64 just build

just test-integration
just integration-tests
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
resolver = "2"

members = [
"./mach",
"./mach-nodejs",
"./crates/*",
]

[profile.release]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions mach-nodejs/src/lib.rs → crates/mach-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::thread;

use ipc_channel_adapter::child::sync::HostReceiver;
use ipc_channel_adapter::child::sync::HostSender;
use mach::public::nodejs::client::NodejsClientRequest;
use mach::public::nodejs::client::NodejsClientResponse;
use mach::public::nodejs::NodejsHostRequest;
use mach::public::nodejs::NodejsHostResponse;
use libmach::public::nodejs::client::NodejsClientRequest;
use libmach::public::nodejs::client::NodejsClientResponse;
use libmach::public::nodejs::NodejsHostRequest;
use libmach::public::nodejs::NodejsHostResponse;
use napi::threadsafe_function::ThreadSafeCallContext;
use napi::threadsafe_function::ThreadsafeFunctionCallMode;
use napi::Env;
Expand Down
2 changes: 1 addition & 1 deletion mach/Cargo.toml → crates/mach/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "mach"
path = "src/main.rs"

[lib]
name = "mach"
name = "libmach"
path = "src/lib.rs"

[dependencies]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions crates/mach/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod kit;
pub mod public;
pub mod platform;
pub mod cmd;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ _default:
build:
# Build mach and napi
cargo build {{profile_cargo}} {{target_cargo}}
@cp ./target/.cargo/{{target}}/{{profile}}/libmach_nodejs.{{dylib}} ./mach-nodejs/lib/napi/index.node
@cp ./target/.cargo/{{target}}/{{profile}}/libmach_nodejs.{{dylib}} ./crates/mach-nodejs/lib/napi/index.node

# Copy output to target
@rm -rf {{out_dir}}
@rm -rf {{out_dir_link}}
@mkdir -p {{out_dir}}
@mkdir -p {{out_dir}}/bin
@cp ./target/.cargo/{{target}}/{{profile}}/mach {{out_dir}}/bin
@cp -r ./mach-nodejs/lib {{out_dir}}/nodejs
@cp -r ./crates/mach-nodejs/lib {{out_dir}}/nodejs
@ln -s {{out_dir}} {{out_dir_link}}

# Prepare local npm package to use local binary
Expand All @@ -105,15 +105,15 @@ build:
build:
# Build mach and napi
cargo build {{profile_cargo}} {{target_cargo}}
@Copy-Item ".\target\.cargo\{{target}}\{{profile}}\mach_nodejs.{{dylib}}" -Destination ".\mach-nodejs\lib\napi\index.node" | Out-Null
@Copy-Item ".\target\.cargo\{{target}}\{{profile}}\mach_nodejs.{{dylib}}" -Destination ".\crates\mach-nodejs\lib\napi\index.node" | Out-Null

# Copy output to target
@if (Test-Path {{out_dir}}) { Remove-Item -Recurse -Force {{out_dir}} | Out-Null }
@if (Test-Path {{out_dir_link}}) { Remove-Item -Recurse -Force {{out_dir_link}} | Out-Null }
@New-Item -ItemType "directory" -Force -Path "{{out_dir}}" | Out-Null
@New-Item -ItemType "directory" -Force -Path "{{out_dir}}\bin" | Out-Null
@Copy-Item ".\target\.cargo\{{target}}\{{profile}}\mach.exe" -Destination "{{out_dir}}\bin" | Out-Null
@Copy-Item ".\mach-nodejs\lib" -Destination "{{out_dir}}\nodejs" -Recurse | Out-Null
@Copy-Item ".\crates\mach-nodejs\lib" -Destination "{{out_dir}}\nodejs" -Recurse | Out-Null
@New-Item -ItemType SymbolicLink -Path "{{out_dir_link}}" -Target "{{out_dir}}" | Out-Null

# Prepare local npm package to use local binary
Expand Down Expand Up @@ -144,7 +144,7 @@ example cmd fixture *ARGS:
serve:
npx http-server -p 3000 ./examples

test-integration:
integration-tests:
cd testing && node --import tsx setup.ts

test:
Expand Down Expand Up @@ -180,7 +180,7 @@ build-publish:
[private]
build-publish-common:
node {{justfile_directory()}}/.github/scripts/ci/string-replace.mjs \
"./mach/Cargo.toml" \
"./crates/mach/Cargo.toml" \
"0.0.0-local" \
{{MACH_VERSION}}

Expand Down
2 changes: 0 additions & 2 deletions mach/src/lib.rs

This file was deleted.

3 changes: 1 addition & 2 deletions npm/mach/lib/mach.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export class Mach {
})

let result = await on_complete
server.close()
child.kill()
await new Promise(res => server.close(() => res()))
return result
}

Expand Down
17 changes: 17 additions & 0 deletions testing/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ import { CHROME_EXECUTABLE_PATH } from './utils/browser/executable.js';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

void async function() {
const browser = await puppeteer.launch({
executablePath: CHROME_EXECUTABLE_PATH,
headless: true,
devtools: true,
ignoreHTTPSErrors: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-sync',
'--ignore-certificate-errors',
'--disable-gpu'
],
})

process.env.PUPPETEER_WS_ENDPOINT = browser.wsEndpoint()

const files = fs.readdirSync(path.join(__dirname, 'tests'))
.filter(test => !test.startsWith('_'))
.map(test => path.join(__dirname, 'tests', test))
Expand All @@ -26,4 +42,5 @@ void async function() {

test_stream.pipe(process.stdout)
await new Promise(res => finished(test_stream, res))
await browser.close()
}()
2 changes: 1 addition & 1 deletion testing/tests/commonjs-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('commonjs-basic', { concurrency: true }, () => {
let report: BuildReport

before(async () => {
await install_npm(FIXTURE())
install_npm(FIXTURE())

report = await Mach.build({
projectRoot: FIXTURE(),
Expand Down
23 changes: 6 additions & 17 deletions testing/tests/web-html-ts-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {test, describe, before, after} from 'node:test';
import * as assert from 'node:assert';
import { BuildReport, Mach } from '@alshdavid/mach';
import { FIXTURES_FN } from '../utils/paths/index.js';
import { CHROME_EXECUTABLE_PATH, ClientContext } from '../utils/browser/index.js';
import { ClientContext } from '../utils/browser/index.js';
import { install_npm } from '../utils/npm/index.js';
import * as puppeteer from 'puppeteer-core';

Expand All @@ -14,36 +14,25 @@ describe('web-html-ts-css', { concurrency: true }, async () => {
let report: BuildReport

before(async () => {
await install_npm(FIXTURE())
install_npm(FIXTURE())

report = await Mach.build({
projectRoot: FIXTURE(),
entries: ['src/index.html']
})

browser = await puppeteer.launch({
executablePath: CHROME_EXECUTABLE_PATH,
headless: true,
devtools: true,
ignoreHTTPSErrors: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-sync',
'--ignore-certificate-errors',
'--disable-gpu'
],
browser = await puppeteer.connect({
browserWSEndpoint: process.env.PUPPETEER_WS_ENDPOINT
})

client = await ClientContext.new({
browser,
serve_path: FIXTURE('dist')
})
})

after(async () => {
await browser.close()
client.close()
await browser.disconnect()
await client.close()
})

test('Should set exports correctly ', async (t) => {
Expand Down
20 changes: 3 additions & 17 deletions testing/utils/browser/client_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,31 @@ import * as fs from "node:fs"
import * as fsAsync from "node:fs/promises"

export type ClientContextOptions = {
browser: puppeteer.Browser
serve_path: string
}

export class ClientContext {
#server
#browser

constructor(
server: http.Server,
browser: puppeteer.Browser,
) {
this.#server = server
this.#browser = browser
}

static async new(options: ClientContextOptions): Promise<ClientContext> {
const server = http.createServer(serve_static(options.serve_path))
await new Promise<void>(res => server.listen(0, "0.0.0.0", () => res()))
return new ClientContext(server, options.browser)
return new ClientContext(server)
}

// async newPage(): Promise<puppeteer.Page & AsyncDisposable & Disposable> {
// const page = await this.#browser.newPage()

// await page.goto(`http://localhost:${this.#server.address().port}`)



// return page as puppeteer.Page & AsyncDisposable & Disposable
// }

address() {
// @ts-expect-error
return `http://localhost:${this.#server.address().port}`
}

close() {
this.#server.close()
async close() {
await new Promise<void>(res => this.#server.close(() => res()))
}
}

Expand Down
9 changes: 2 additions & 7 deletions testing/utils/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import path from 'node:path';
import child_process from 'node:child_process';
import fs from 'node:fs';

export async function install_npm(cwd: string): Promise<void> {
export function install_npm(cwd: string): void {
if (!fs.existsSync(cwd)) {
throw new Error(`Error Does Not Exist: ${cwd}`)
}

if (!fs.existsSync(path.join(cwd, 'node_modules'))) {
await new Promise((resolve, reject) => {
child_process.exec(`npm install --no-package-lock`, { cwd }, (err, stdout) => {
if (err) return reject(err)
resolve(stdout)
})
})
child_process.execSync(`npm install --no-package-lock`, { cwd })
}
}