chore: downgrade scripts support to node 12 (#473)

From start scripts needed to be run with node 13 (esm support)
Because data.js was a esm export, and needed to be compiled
Moved all scripts to commontjs, and data.js file
So can be imported by scripts without compiling
This commit is contained in:
Andrew Luca 2020-01-20 22:37:32 +02:00 committed by GitHub
parent 2c1e9a5d5b
commit 7893bc510c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 25 deletions

View file

@ -3,7 +3,7 @@ module.exports = {
title: `/uses`, title: `/uses`,
description: `A list of /uses pages detailing developer setups.`, description: `A list of /uses pages detailing developer setups.`,
author: `@wesbos`, author: `@wesbos`,
siteUrl: "https://uses.tech", siteUrl: 'https://uses.tech',
}, },
plugins: [ plugins: [
{ {

View file

@ -3,12 +3,14 @@
"description": "What do you uses", "description": "What do you uses",
"version": "7.7.7", "version": "7.7.7",
"author": "Wes Bos", "author": "Wes Bos",
"type": "module",
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"wesbos" "wesbos"
] ]
}, },
"engines": {
"node": ">= 12"
},
"dependencies": { "dependencies": {
"@actions/core": "^1.2.1", "@actions/core": "^1.2.1",
"@actions/exec": "^1.0.3", "@actions/exec": "^1.0.3",

View file

@ -1,6 +1,6 @@
import core from '@actions/core'; const core = require('@actions/core');
import { getMasterData, Schema, getStatusCode } from './utils.js'; const { getMasterData, Schema, getStatusCode } = require('./utils.js');
import srcData from '../src/data.js'; const srcData = require('../src/data.js');
(async () => { (async () => {
// on master branch will be empty array // on master branch will be empty array
@ -19,7 +19,7 @@ import srcData from '../src/data.js';
}); });
let failedUrlsCount = 0; let failedUrlsCount = 0;
for await (const { url } of data) { for (const { url } of data) {
try { try {
const statusCode = await getStatusCode(url); const statusCode = await getStatusCode(url);
if (statusCode < 200 || statusCode >= 400) { if (statusCode < 200 || statusCode >= 400) {

View file

@ -1,4 +1,4 @@
const flags = [ module.exports = [
'🇦🇫', '🇦🇫',
'🇦🇱', '🇦🇱',
'🇩🇿', '🇩🇿',
@ -236,5 +236,3 @@ const flags = [
'🏳️‍🌈', '🏳️‍🌈',
'🇪🇺', '🇪🇺',
]; ];
export default flags;

View file

@ -2,4 +2,4 @@
* this is a stub file, do not edit it * this is a stub file, do not edit it
* see `scripts/utils.js` -> `getMasterData` * see `scripts/utils.js` -> `getMasterData`
*/ */
export default []; module.exports = [];

View file

@ -1,5 +1,5 @@
import fs from 'fs'; const fs = require('fs');
import data from '../src/data.js'; const data = require('../src/data.js');
/** @type {string} */ /** @type {string} */
const readmeTemplate = fs.readFileSync('./scripts/readme-template.md', 'utf8'); const readmeTemplate = fs.readFileSync('./scripts/readme-template.md', 'utf8');

View file

@ -1,9 +1,9 @@
import exec from '@actions/exec'; const exec = require('@actions/exec');
import core from '@actions/core'; const core = require('@actions/core');
import Joi from '@hapi/joi'; const Joi = require('@hapi/joi');
import * as http from 'http'; const http = require('http');
import * as https from 'https'; const https = require('https');
import flags from './flags.js'; const flags = require('./flags.js');
async function getCurrentBranchName() { async function getCurrentBranchName() {
let myOutput = ''; let myOutput = '';
@ -22,7 +22,7 @@ async function getCurrentBranchName() {
} }
/** on master branch will return an empty array */ /** on master branch will return an empty array */
export async function getMasterData() { module.exports.getMasterData = async function() {
const options = { silent: true }; const options = { silent: true };
const curentBranchName = await getCurrentBranchName(); const curentBranchName = await getCurrentBranchName();
// when on a branch/PR different from master // when on a branch/PR different from master
@ -38,7 +38,8 @@ export async function getMasterData() {
core.info('Executing action on master branch'); core.info('Executing action on master branch');
} }
const masterData = await import('./masterData.js').then(m => m.default); // eslint-disable-next-line global-require
const masterData = require('./masterData.js');
// restore `scripts/masterData.js` after was loaded // restore `scripts/masterData.js` after was loaded
if (curentBranchName !== 'master') { if (curentBranchName !== 'master') {
@ -46,9 +47,9 @@ export async function getMasterData() {
} }
return masterData; return masterData;
} };
export const Schema = Joi.object({ module.exports.Schema = Joi.object({
name: Joi.string().required(), name: Joi.string().required(),
description: Joi.string().required(), description: Joi.string().required(),
url: Joi.string() url: Joi.string()
@ -65,7 +66,7 @@ export const Schema = Joi.object({
tags: Joi.array().items(Joi.string()), tags: Joi.array().items(Joi.string()),
}); });
export function getStatusCode(url) { module.exports.getStatusCode = function(url) {
const client = url.startsWith('https') ? https : http; const client = url.startsWith('https') ? https : http;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const REQUEST_TIMEOUT = 10000; const REQUEST_TIMEOUT = 10000;
@ -82,4 +83,4 @@ export function getStatusCode(url) {
}) })
.on('error', err => reject(err)); .on('error', err => reject(err));
}); });
} };

View file

@ -1,4 +1,5 @@
export default [ // keep it commonjs export
module.exports = [
{ {
name: 'Wes Bos', name: 'Wes Bos',
description: description: