From 7d72e0c046043afaf436f8c9f23f1ce292aa7a59 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Thu, 16 Jan 2020 02:05:24 +0100 Subject: [PATCH] Convert clean-shrinkwrap.js to typescript Change-type: patch --- Makefile | 7 ++--- package.json | 4 +-- scripts/clean-shrinkwrap.js | 37 ---------------------- scripts/clean-shrinkwrap.ts | 48 +++++++++++++++++++++++++++++ typings/omit-deep-lodash/index.d.ts | 1 + 5 files changed, 53 insertions(+), 44 deletions(-) delete mode 100644 scripts/clean-shrinkwrap.js create mode 100644 scripts/clean-shrinkwrap.ts create mode 100644 typings/omit-deep-lodash/index.d.ts diff --git a/Makefile b/Makefile index cb460f26..bd1231da 100644 --- a/Makefile +++ b/Makefile @@ -150,10 +150,7 @@ sass: node-sass lib/gui/app/scss/main.scss > lib/gui/css/main.css lint-ts: - resin-lint --typescript lib tests webpack.config.ts - -lint-js: - eslint --ignore-pattern scripts/resin/**/*.js scripts + resin-lint --typescript lib tests scripts/clean-shrinkwrap.ts webpack.config.ts lint-sass: sass-lint lib/gui/scss @@ -168,7 +165,7 @@ lint-spell: --skip *.svg *.gz,*.bz2,*.xz,*.zip,*.img,*.dmg,*.iso,*.rpi-sdcard,*.wic,.DS_Store,*.dtb,*.dtbo,*.dat,*.elf,*.bin,*.foo,xz-without-extension \ lib tests docs Makefile *.md LICENSE -lint: lint-ts lint-js lint-sass lint-cpp lint-spell +lint: lint-ts lint-sass lint-cpp lint-spell MOCHA_OPTIONS=--recursive --reporter spec --require ts-node/register diff --git a/package.json b/package.json index 30b6417a..1d52086e 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ }, "scripts": { "test": "make lint test sanity-checks", - "prettier": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"lib/**/*.ts\" \"lib/**/*.tsx\" \"tests/**/*.ts\" \"webpack.config.ts\"", + "prettier": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"lib/**/*.ts\" \"lib/**/*.tsx\" \"tests/**/*.ts\" \"webpack.config.ts\" \"scripts/clean-shrinkwrap.ts\"", "start": "./node_modules/.bin/electron .", - "postshrinkwrap": "node ./scripts/clean-shrinkwrap.js", + "postshrinkwrap": "ts-node ./scripts/clean-shrinkwrap.ts", "configure": "node-gyp configure", "build": "node-gyp build", "install": "node-gyp rebuild", diff --git a/scripts/clean-shrinkwrap.js b/scripts/clean-shrinkwrap.js deleted file mode 100644 index 66e985c1..00000000 --- a/scripts/clean-shrinkwrap.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * This script is in charge of cleaning the `shrinkwrap` file. - * - * `npm shrinkwrap` has a bug where it will add optional dependencies - * to `npm-shrinkwrap.json`, therefore causing errors if these optional - * dependendencies are platform dependent and you then try to build - * the project in another platform. - * - * As a workaround, we keep a list of platform dependent dependencies in - * the `platformSpecificDependencies` property of `package.json`, - * and manually remove them from `npm-shrinkwrap.json` if they exist. - * - * See: https://github.com/npm/npm/issues/2679 - */ - -'use strict' - -const fs = require('fs') -const path = require('path') -const omit = require('omit-deep-lodash') - -const JSON_INDENT = 2 -const SHRINKWRAP_FILENAME = path.join(__dirname, '..', 'npm-shrinkwrap.json') - -const packageInfo = require('../package.json') -const shrinkwrap = require('../npm-shrinkwrap.json') - -const cleaned = omit(shrinkwrap, packageInfo.platformSpecificDependencies) - -fs.writeFile(SHRINKWRAP_FILENAME, JSON.stringify(cleaned, null, JSON_INDENT), (error) => { - if (error) { - console.log(`[ERROR] Couldn't write shrinkwrap file: ${error.stack}`) - process.exitCode = 1 - } else { - console.log(`[OK] Wrote shrinkwrap file to ${path.relative(__dirname, SHRINKWRAP_FILENAME)}`) - } -}) diff --git a/scripts/clean-shrinkwrap.ts b/scripts/clean-shrinkwrap.ts new file mode 100644 index 00000000..0b442fbf --- /dev/null +++ b/scripts/clean-shrinkwrap.ts @@ -0,0 +1,48 @@ +/** + * This script is in charge of cleaning the `shrinkwrap` file. + * + * `npm shrinkwrap` has a bug where it will add optional dependencies + * to `npm-shrinkwrap.json`, therefore causing errors if these optional + * dependendencies are platform dependent and you then try to build + * the project in another platform. + * + * As a workaround, we keep a list of platform dependent dependencies in + * the `platformSpecificDependencies` property of `package.json`, + * and manually remove them from `npm-shrinkwrap.json` if they exist. + * + * See: https://github.com/npm/npm/issues/2679 + */ + +import { writeFile } from 'fs'; +import * as omit from 'omit-deep-lodash'; +import * as path from 'path'; +import { promisify } from 'util'; + +import * as shrinkwrap from '../npm-shrinkwrap.json'; +import * as packageInfo from '../package.json'; + +const writeFileAsync = promisify(writeFile); + +const JSON_INDENT = 2; +const SHRINKWRAP_FILENAME = path.join(__dirname, '..', 'npm-shrinkwrap.json'); + +async function main() { + try { + const cleaned = omit(shrinkwrap, packageInfo.platformSpecificDependencies); + await writeFileAsync( + SHRINKWRAP_FILENAME, + JSON.stringify(cleaned, null, JSON_INDENT), + ); + } catch (error) { + console.log(`[ERROR] Couldn't write shrinkwrap file: ${error.stack}`); + process.exitCode = 1; + } + console.log( + `[OK] Wrote shrinkwrap file to ${path.relative( + __dirname, + SHRINKWRAP_FILENAME, + )}`, + ); +} + +main(); diff --git a/typings/omit-deep-lodash/index.d.ts b/typings/omit-deep-lodash/index.d.ts new file mode 100644 index 00000000..07b16604 --- /dev/null +++ b/typings/omit-deep-lodash/index.d.ts @@ -0,0 +1 @@ +declare module 'omit-deep-lodash';