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

fix: Include not working with deno runtime #2704

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .gitattributes

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

2 changes: 1 addition & 1 deletion .gitignore

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

2 changes: 1 addition & 1 deletion .projen/tasks.json

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

6 changes: 3 additions & 3 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const project = new Cdk8sTeamJsiiProject({
jsiiVersion: '^5',
});

// _loadurl.js is written in javascript so we need to commit it and also copy it
// _loadurl.mjs is written in javascript so we need to commit it and also copy it
// after compilation to the `lib/` directory.
project.gitignore.include('/src/_loadurl.js');
project.compileTask.exec('cp src/_loadurl.js lib/');
project.gitignore.include('/src/_loadurl.mjs');
project.compileTask.exec('cp src/_loadurl.mjs lib/');

const installHelm = project.addTask('install-helm', {
exec: 'curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash',
Expand Down
19 changes: 11 additions & 8 deletions src/_loadurl.js → src/_loadurl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
// ctors). so we utilize `spawnSync` to spawn this program as a child process.
// alternatively we could have use `curl` but this is more portable.

const { http, https } = require('follow-redirects');
const { parse } = require('url');
const fs = require('fs');
import followRedirects from 'follow-redirects';
import { parse } from 'node:url';
import { lstatSync, createReadStream } from 'node:fs';
import process from 'node:process'

const { http, https } = followRedirects;

const url = process.argv[2];
if (!url) {
Expand All @@ -16,25 +19,25 @@ if (!url) {
}

try {
if (fs.lstatSync(url).isFile()) {
fs.createReadStream(url).pipe(process.stdout);
if (lstatSync(url).isFile()) {
createReadStream(url).pipe(process.stdout);
}
} catch (err) {
const purl = parse(url);

if (!purl.protocol) {
throw new Error(`unable to determine protocol from url: ${url}`);
}

const client = getHttpClient(purl.protocol);
const get = client.get(url, response => {
if (response.statusCode !== 200) {
throw new Error(`${response.statusCode} response from http get: ${response.statusMessage}`);
}

response.on('data', chunk => process.stdout.write(chunk));
});

get.once('error', err => {
throw new Error(`http error: ${err.message}`);
});
Expand Down
4 changes: 2 additions & 2 deletions src/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Yaml {
if (obj === undefined) { continue; }
if (obj === null) { continue; }
if (Array.isArray(obj) && obj.length === 0) { continue; }
if (typeof(obj) === 'object' && Object.keys(obj).length === 0) { continue; }
if (typeof (obj) === 'object' && Object.keys(obj).length === 0) { continue; }

result.push(obj);
}
Expand All @@ -103,7 +103,7 @@ export class Yaml {
* This method spawns a child process in order to perform an http call synchronously.
*/
function loadurl(url: string): string {
const script = path.join(__dirname, '_loadurl.js');
const script = path.join(__dirname, '_loadurl.mjs');
return execFileSync(process.execPath, [script, url], {
encoding: 'utf-8',
maxBuffer: MAX_DOWNLOAD_BUFFER,
Expand Down
Loading