Skip to content
Closed
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
4 changes: 4 additions & 0 deletions .github/workflows/run-nitrogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
- name: Build all packages
run: bun run build

- name: Test Nitrogen CLI
working-directory: packages/nitrogen
run: bun test

- name: Run nitrogen in packages/react-native-nitro-test-external
working-directory: packages/react-native-nitro-test-external
run: bun i && bun specs
Expand Down
3 changes: 2 additions & 1 deletion packages/nitrogen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"scripts": {
"build": "bun tsc",
"start": "tsc && node lib/index.js",
"typecheck": "tsc --noEmit",
"test": "bun test",
"typecheck": "tsc --noEmit && tsc -p tests/tsconfig.json",
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions --max-warnings 0",
"release": "release-it"
Expand Down
15 changes: 10 additions & 5 deletions packages/nitrogen/src/config/NitroConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ export class NitroConfig {
this.config = config
}

static load(configPath: string): NitroConfig {
console.log(
chalk.reset(`🔧 Loading ${chalk.underline(configPath)} config...`)
)
const config = readUserConfig(configPath)
this.singleton = new NitroConfig(config)
return this.singleton
}

static get current(): NitroConfig {
if (this.singleton == null) {
console.log(
chalk.reset(`🔧 Loading ${chalk.underline('nitro.json')} config...`)
)
const defaultConfigPath = './nitro.json'
const config = readUserConfig(defaultConfigPath)
this.singleton = new NitroConfig(config)
this.singleton = this.load(defaultConfigPath)
}
return this.singleton
}
Expand Down
2 changes: 2 additions & 0 deletions packages/nitrogen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { promises as fs } from 'fs'
import { isValidLogLevel, setLogLevel } from './Logger.js'
import { initNewNitroModule } from './init.js'
import { NITROGEN_VERSION } from './config/nitrogenVersion.js'
import { NitroConfig } from './config/NitroConfig.js'

const commandName = 'nitrogen'

Expand Down Expand Up @@ -57,6 +58,7 @@ await yargs(hideBin(process.argv))
async (argv) => {
const basePath = argv.basePath
const outputDirectory = argv.out
NitroConfig.load(argv.config)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that's not safe and just prone to races.

await runNitrogenCommand(basePath, outputDirectory)
}
)
Expand Down
48 changes: 48 additions & 0 deletions packages/nitrogen/tests/config-option.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect, test } from 'bun:test'
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import path from 'node:path'

test('loads the configuration passed through --config', async () => {
const workingDirectory = await mkdtemp(
path.join(tmpdir(), 'nitrogen-config-option-')
)
const configPath = path.join(workingDirectory, 'custom-config.json')
const cliPath = path.resolve(import.meta.dir, '../src/index.ts')

try {
await writeFile(
configPath,
JSON.stringify({
cxxNamespace: ['custom'],
ios: { iosModuleName: 'CustomModule' },
android: {
androidNamespace: ['custom'],
androidCxxLibName: 'CustomModule',
},
autolinking: {},
})
)

const child = Bun.spawn(
[process.execPath, cliPath, workingDirectory, '--config', configPath],
{
cwd: workingDirectory,
stdout: 'pipe',
stderr: 'pipe',
}
)
const [stdout, stderr] = await Promise.all([
new Response(child.stdout).text(),
new Response(child.stderr).text(),
child.exited,
])
const output = stdout + stderr

expect(output).toContain('custom-config.json')
expect(output).toContain("Nitrogen didn't find any spec files")
expect(output).not.toContain('The path ./nitro.json does not exist')
} finally {
await rm(workingDirectory, { recursive: true, force: true })
}
})
10 changes: 10 additions & 0 deletions packages/nitrogen/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"include": ["."],
"compilerOptions": {
"composite": false,
"noEmit": true,
"rootDir": ".",
"types": ["bun", "node"]
}
}