From c6bf4556b1d9a2db3d188f61be341ea66c5140f6 Mon Sep 17 00:00:00 2001 From: Jean-Pascal <jean-pascal.aubry@inrae.fr> Date: Fri, 17 Nov 2023 15:03:00 +0000 Subject: [PATCH 1/2] refactor: replace commonjs by ecmascript 2015 refs: #631 --- e2e/load-save-session.e2e-spec.ts | 6 +++--- e2e/tsconfig.e2e.json | 2 +- main.js | 11 ++++++++++- scripts/check-translations.js | 2 +- scripts/clean_release.js | 4 ++-- scripts/extract-nghyd-version.js | 4 ++-- scripts/mkdocs-postprocess.js | 5 +++-- scripts/mkdocs2pdf-postprocess.js | 2 +- scripts/preprocessors.js | 8 +++++--- scripts/sessionDeflate.js | 5 +++-- scripts/update-dist-index-mimetypes.js | 2 +- src/polyfills.ts | 3 ++- 12 files changed, 34 insertions(+), 20 deletions(-) diff --git a/e2e/load-save-session.e2e-spec.ts b/e2e/load-save-session.e2e-spec.ts index 29c1cc67a..1e2576170 100644 --- a/e2e/load-save-session.e2e-spec.ts +++ b/e2e/load-save-session.e2e-spec.ts @@ -7,9 +7,9 @@ import { PreferencesPage } from "./preferences.po"; import { changeSelectValue, expectNumber, loadSession, openCalculator } from "./util.po"; import { browser, $, $$, expect } from '@wdio/globals' -const fs = require("fs"); -const path = require("path"); -const os = require("os"); +import * as fs from 'fs'; +import * as path from 'path'; +import * as os from 'os'; let startPage: AppPage; let listPage: ListPage; diff --git a/e2e/tsconfig.e2e.json b/e2e/tsconfig.e2e.json index 6841529a9..b79ae71f3 100644 --- a/e2e/tsconfig.e2e.json +++ b/e2e/tsconfig.e2e.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "../out-tsc/e2e", "baseUrl": "./", - "module": "commonjs", + "module": "es2015", "downlevelIteration": true, "types": [ "jasmine", diff --git a/main.js b/main.js index bdd10ff5a..675fd2b94 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,13 @@ -const { app, dialog, shell, net, BrowserWindow, Notification, nativeImage } = require('electron'); +import { + app, + dialog, + shell, + net, + BrowserWindow, + Notification, + nativeImage + } from 'electron'; + let win; diff --git a/scripts/check-translations.js b/scripts/check-translations.js index 99b0058dc..758468556 100644 --- a/scripts/check-translations.js +++ b/scripts/check-translations.js @@ -9,7 +9,7 @@ * in all language files */ -const fs = require('fs'); +import * as fs from 'fs'; /* IMPORTANT: during step 2, will look for those languages codes only */ const expectedLanguages = [ "fr", "en" ]; diff --git a/scripts/clean_release.js b/scripts/clean_release.js index d95e7fda1..83d5f9cba 100644 --- a/scripts/clean_release.js +++ b/scripts/clean_release.js @@ -1,7 +1,7 @@ 'use strict'; -const fs = require('fs'); -const rimraf = require('rimraf'); +import * as fs from 'fs'; +import * as rimraf from 'rimraf'; const path = './release'; diff --git a/scripts/extract-nghyd-version.js b/scripts/extract-nghyd-version.js index aff3a3dd0..3f303a7e8 100644 --- a/scripts/extract-nghyd-version.js +++ b/scripts/extract-nghyd-version.js @@ -6,8 +6,8 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); +import * as fs from 'fs'; +import * as path from 'path'; if (process.argv.length < 3) { console.error("ERROR : missing output file path(s)\n"); diff --git a/scripts/mkdocs-postprocess.js b/scripts/mkdocs-postprocess.js index 11b259033..97defa3d5 100644 --- a/scripts/mkdocs-postprocess.js +++ b/scripts/mkdocs-postprocess.js @@ -4,7 +4,8 @@ * copies extra javascripts (MathJax, matomo-tracking) to src/assets/docs/javascripts after doc was built by MkDocs */ -const fs = require('fs-extra'); +import * as fs from 'fs-extra'; + const destPath_JS = "src/assets/docs/javascripts"; const destPath_CSS = "src/assets/docs/stylesheets"; @@ -44,7 +45,7 @@ de niveau de répertoire. La solution est donc de modifier les fichiers HTML générés pour ajouter ../ dans href="...". */ -const cp = require('child_process'); +import * as cp from 'child_process'; function execBashCmd(cmd) { // console.log(cmd); diff --git a/scripts/mkdocs2pdf-postprocess.js b/scripts/mkdocs2pdf-postprocess.js index 0752898f8..130d739c4 100644 --- a/scripts/mkdocs2pdf-postprocess.js +++ b/scripts/mkdocs2pdf-postprocess.js @@ -5,7 +5,7 @@ * - copy illustrated guide (not related to MkDocs, but still a part of the doc) to dist/assets/docs/pdf */ -const fs = require('fs-extra'); +import * as fs from 'fs-extra'; const destPath_PDF = "dist/assets/docs/pdf"; // pour la doc illustrée diff --git a/scripts/preprocessors.js b/scripts/preprocessors.js index e95d481c3..da5bbfc91 100644 --- a/scripts/preprocessors.js +++ b/scripts/preprocessors.js @@ -3,11 +3,13 @@ * */ -var fs = require('fs'); -date_last_commit = require('child_process') +import * as fs from 'fs'; +import * as cp from 'child_process'; + +date_last_commit = cp .execSync('git log -1 --format=%cd --date=short') .toString().trim() -version = require('child_process') +version = cp .execSync('git describe') .toString().trim() diff --git a/scripts/sessionDeflate.js b/scripts/sessionDeflate.js index 212360a62..1e794f6fc 100644 --- a/scripts/sessionDeflate.js +++ b/scripts/sessionDeflate.js @@ -7,8 +7,9 @@ 'use strict'; -const pako = require("pako"); -global.atob = require("atob"); +import * as pako from 'pako'; +import * as atob from 'atob'; +global.atob = atob; const stdin = process.openStdin(); diff --git a/scripts/update-dist-index-mimetypes.js b/scripts/update-dist-index-mimetypes.js index 7e35416d7..bc3e681eb 100644 --- a/scripts/update-dist-index-mimetypes.js +++ b/scripts/update-dist-index-mimetypes.js @@ -1,6 +1,6 @@ 'use strict'; -const fs = require('fs'); +import * as fs from 'fs'; const path = "./dist/index.html"; const contents = fs.readFileSync(path, "utf-8"); diff --git a/src/polyfills.ts b/src/polyfills.ts index c9ef31b81..aac924fce 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -66,7 +66,8 @@ import "zone.js"; // Included with Angular CLI. // Requis pour Buffer dans jalhyd (!?) (window as any).global = window; -global.Buffer = global.Buffer || require("buffer").Buffer; +import * as buffer from 'buffer'; +global.Buffer = global.Buffer || buffer.Buffer; // Edge polyfill for canvas.toBlob method if (!HTMLCanvasElement.prototype.toBlob) { -- GitLab From d7833974aaf0d3cf8e769bae45f3f4f22acafa8a Mon Sep 17 00:00:00 2001 From: Jean-Pascal <jean-pascal.aubry@inrae.fr> Date: Fri, 17 Nov 2023 15:38:58 +0000 Subject: [PATCH 2/2] fix: add "type": "module" in package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b978f2097..01702506a 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "main": "main.js", "homepage": "https://cassiopee.g-eau.fr", "license": "MIT", + "type": "module", "scripts": { "ng": "cd . && \"node_modules/.bin/ng\"", "postinstall": "./node_modules/.bin/webdriver-manager update --gecko=false --versions.chrome=107.0.5304.110", -- GitLab