Skip to content

Commit

Permalink
Added node: prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Apr 3, 2024
1 parent e61d19d commit ddccb19
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-donkeys-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@kitajs/fastify-html-plugin': patch
'@kitajs/ts-html-plugin': patch
'@kitajs/html': patch
---

Added node: prefix
2 changes: 1 addition & 1 deletion packages/fastify-html-plugin/examples/htmx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fastifyFormbody from '@fastify/formbody';
import { Suspense } from '@kitajs/html/suspense';
import fastify from 'fastify';
import { setTimeout } from 'timers/promises';
import { setTimeout } from 'node:timers/promises';
import { fastifyKitaHtml } from '..';

const app = fastify({ logger: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/html/suspense.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Readable } from 'stream';
import type { Readable } from 'node:stream';
import type { Children } from './';

declare global {
Expand Down
8 changes: 4 additions & 4 deletions packages/html/suspense.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { contentsToString, contentToString } = require('./index');
const { Readable } = require('stream');
const { Readable } = require('node:stream');

// Avoids double initialization in case this file is not cached by
// module bundlers.
Expand Down Expand Up @@ -169,11 +169,11 @@ function Suspense(props) {

// Keeps string return type
if (typeof fallback === 'string') {
return '<div id="B:' + run + '" data-sf>' + fallback + '</div>';
return `<div id="B:${run}" data-sf>${fallback}</div>`;
}

return fallback.then(function resolveCallback(resolved) {
return '<div id="B:' + run + '" data-sf>' + resolved + '</div>';
return `<div id="B:${run}" data-sf>${resolved}</div>`;
});

/**
Expand Down Expand Up @@ -204,7 +204,7 @@ function Suspense(props) {
// Writes the chunk
data.stream.push(
// prettier-ignore
'<template id="N:' + run + '" data-sr>' + result + '</template><script id="S:' + run + '" data-ss>$KITA_RC(' + run + ')</script>'
`<template id="N:${run}" data-sr>${result}</template><script id="S:${run}" data-ss>$KITA_RC(${run})</script>`
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/ts-html-plugin/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node

import chalk from 'chalk';
import fs from 'fs';
import { EOL } from 'os';
import path from 'path';
import fs from 'node:fs';
import { EOL } from 'node:os';
import path from 'node:path';
import ts from 'typescript';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
Expand Down Expand Up @@ -166,7 +166,7 @@ async function main() {
files = [];

for (let i = 0; i < args._.length; i++) {
let file = String(args._[i]);
const file = String(args._[i]);

if (!fileExists(file)) {
console.error(
Expand All @@ -189,7 +189,7 @@ async function main() {
}

if (!files.length) {
console.error((!simplified ? chalk.red : String)(`No files were found to check.`));
console.error((!simplified ? chalk.red : String)('No files were found to check.'));
return process.exit(1);
}

Expand Down
29 changes: 14 additions & 15 deletions packages/ts-html-plugin/test/util/lang-server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChildProcess, fork } from 'child_process';
import { EventEmitter } from 'events';
import { Deferred, deferred } from 'fast-defer';
import { statSync } from 'fs';
import path from 'path';
import { deferred, type Deferred } from 'fast-defer';
import { fork, type ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
import { statSync } from 'node:fs';
import path from 'node:path';
import ts from 'typescript/lib/tsserverlibrary';

/** All requests used in tests */
Expand Down Expand Up @@ -82,9 +82,9 @@ export class TSLangServer {
this.server.on('exit', this.exitPromise.resolve);
this.server.on('error', this.exitPromise.reject);

this.server.stdout!.setEncoding('utf-8');
this.server.stdout?.setEncoding('utf-8');

this.server.stdout!.on('data', (data) => {
this.server.stdout?.on('data', (data) => {
const obj = JSON.parse(data.split('\n', 3)[2]);

if (this.debug) {
Expand All @@ -97,7 +97,7 @@ export class TSLangServer {
// Error is fatal, close the server
if (!this.isClosed) {
this.isClosed = true;
this.server.stdin!.end();
this.server.stdin?.end();
}
} else if (obj.type === 'event') {
this.responseEventEmitter.emit(obj.event, obj);
Expand All @@ -109,7 +109,7 @@ export class TSLangServer {

/** Opens the project, sends diagnostics request and returns the response */
async openWithDiagnostics(content: TemplateStringsArray, ...args: any[]) {
const fileContent = TEST_HELPERS + '\n' + String.raw(content, ...args).trim();
const fileContent = `${TEST_HELPERS}\n${String.raw(content, ...args).trim()}`;

if (this.debug) {
console.log(this.strWithLineNumbers(fileContent));
Expand Down Expand Up @@ -147,18 +147,17 @@ export class TSLangServer {
send(command: Omit<Requests, 'seq' | 'type'>) {
const response = deferred<void>();

this.server.stdin!.write(this.formatCommand(command), (err) =>
this.server.stdin?.write(this.formatCommand(command), (err) =>
err ? response.reject(err) : response.resolve()
);

return response;
}

private formatCommand(command: Omit<Requests, 'seq' | 'type'>) {
return (
JSON.stringify(Object.assign({ seq: ++this.sequence, type: 'request' }, command)) +
'\n'
);
return `${JSON.stringify(
Object.assign({ seq: ++this.sequence, type: 'request' }, command)
)}\n`;
}

waitEvent(eventName: string) {
Expand Down Expand Up @@ -198,7 +197,7 @@ export class TSLangServer {
[Symbol.asyncDispose]() {
if (!this.isClosed) {
this.isClosed = true;
this.server.stdin!.end();
this.server.stdin?.end();
}

return this.exitPromise;
Expand Down

0 comments on commit ddccb19

Please sign in to comment.