Skip to content

Commit ab3f2b5

Browse files
committed
[frontend] Update to ESM (#14044)
1 parent 8e2542f commit ab3f2b5

File tree

18 files changed

+94
-131
lines changed

18 files changed

+94
-131
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ python3 src/worker.py # Start worker
127127
opencti/
128128
├── opencti-platform/
129129
│ ├── .yarnrc.yml # MUST copy to subdirs
130-
│ ├── opencti-graphql/ # Backend: src/, config/, tests/, vitest.config.*.ts, eslint.config.mjs
130+
│ ├── opencti-graphql/ # Backend: src/, config/, tests/, vitest.config.*.ts, eslint.config.js
131131
│ ├── opencti-front/ # Frontend: src/, tests_e2e/, lang/, relay.config.json
132132
│ └── opencti-dev/docker-compose.yml
133133
├── client-python/ # pycti/, tests/, pyproject.toml, .flake8, .isort.cfg
134134
├── opencti-worker/src/
135135
└── scripts/ci/ # docker-compose.yml, ci-common.env
136136
```
137137

138-
**Key Configs**: `eslint.config.mjs` (v9), `tsconfig.json` (strict), `vitest.config.*`, `.flake8`, `.isort.cfg`, `pyproject.toml`
138+
**Key Configs**: `eslint.config.js` (v9), `tsconfig.json` (strict), `vitest.config.*`, `.flake8`, `.isort.cfg`, `pyproject.toml`
139139

140140
## Common Pitfalls & Solutions
141141

opencti-platform/opencti-front/builder/dev/dev.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
const express = require("express");
2-
const { createProxyMiddleware } = require("http-proxy-middleware");
3-
const { cp, readFile } = require("node:fs/promises")
4-
const path = require("node:path");
5-
const esbuild = require("esbuild");
6-
const chokidar = require("chokidar");
7-
const compression = require("compression");
8-
const { RelayPlugin } = require("../plugin/esbuild-relay");
1+
import express from 'express';
2+
import { createProxyMiddleware } from 'http-proxy-middleware';
3+
import { cp, readFile } from 'node:fs/promises'
4+
import path from 'node:path';
5+
import esbuild from 'esbuild';
6+
import chokidar from 'chokidar';
7+
import compression from 'compression';
8+
import { RelayPlugin } from '../plugin/esbuild-relay.js';
9+
import { fileURLToPath } from 'node:url'
10+
11+
const __filename = fileURLToPath(import.meta.url)
12+
const __dirname = path.dirname(__filename)
913

1014
const basePath = "";
1115
const clients = [];

opencti-platform/opencti-front/builder/plugin/esbuild-relay.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
const {promises} = require('fs');
2-
const crypto = require('crypto');
3-
const {print, parse} = require('graphql');
1+
import { readFile } from 'node:fs/promises';
2+
import crypto from 'crypto';
3+
import { print, parse } from 'graphql';
44

5-
module.exports.RelayPlugin = {
5+
export const RelayPlugin = {
66
name: 'relay',
77
setup: (build) => {
88
build.onLoad({filter: /\.(js|tsx|jsx)$/, namespace: "file"}, async (args) => {
99
let contents;
1010
if (args.path.includes('src') && !args.path.includes('node_modules') && !args.path.includes('__generated__')) {
11-
contents = await promises.readFile(args.path, 'utf8');
11+
contents = await readFile(args.path, 'utf8');
1212
if (contents.includes('graphql`')) {
1313
const imports = [];
1414
contents = contents.replaceAll(/\sgraphql`([\s\S]*?)`/gm, (match, query) => {

opencti-platform/opencti-front/builder/prod/prod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const esbuild = require("esbuild");
2-
const { cp, rename, rm, readdir, writeFile } = require("node:fs/promises")
3-
const { RelayPlugin } = require("../plugin/esbuild-relay");
1+
import esbuild from 'esbuild';
2+
import { cp, rename, rm, readdir, writeFile } from 'node:fs/promises'
3+
import { RelayPlugin } from '../plugin/esbuild-relay.js';
44

55
// Define args options
66
const keep = process.argv.slice(2).includes('--keep');

opencti-platform/opencti-front/eslint.config.mjs renamed to opencti-platform/opencti-front/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineConfig([
2020
'**/src/static/ext/**',
2121
'extract-i18n-keyword.js',
2222
'playwright.config.ts',
23-
'vite.config.mts',
23+
'vite.config.ts',
2424
'vitest.config.ts',
2525
'setup-vitest.ts',
2626
],
@@ -63,7 +63,7 @@ export default defineConfig([
6363
{
6464
plugins: {
6565
'import-newlines': importNewlines,
66-
'custom-rules': customRules,
66+
'custom-rules': { rules: customRules },
6767
'@stylistic': stylistic,
6868
},
6969
},

opencti-platform/opencti-front/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "opencti-front",
33
"version": "6.9.8",
44
"private": true,
5+
"type": "module",
56
"workspaces": [
67
"packages/*"
78
],
@@ -13,7 +14,7 @@
1314
"esbuild": "node builder/prod/prod.js",
1415
"build": "yarn relay && yarn esbuild",
1516
"build:standalone": "yarn relay && yarn esbuild --keep",
16-
"lint": "DEBUG=eslint:cli-engine TIMING=1 eslint --quiet --cache --config eslint.config.mjs src",
17+
"lint": "DEBUG=eslint:cli-engine TIMING=1 eslint --quiet --cache --config eslint.config.js src",
1718
"control": "yarn audit --groups dependencies --summary",
1819
"test": "vitest run",
1920
"test:watch": "vitest watch",
@@ -192,9 +193,6 @@
192193
"three": "0.181.2"
193194
},
194195
"dependenciesMeta": {
195-
"canvas": {
196-
"built": false
197-
},
198196
"core-js": {
199197
"built": false
200198
},
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
const requireIndex = require("requireindex");
2-
module.exports.rules = requireIndex(__dirname + "/rules");
1+
import classesRules from './rules/classes-rule.js';
2+
3+
export default {
4+
'classes-rule': classesRules,
5+
};

opencti-platform/opencti-front/packages/eslint-plugin-custom-rules/lib/rules/classes-rule.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
const rule = {
22
meta: {
33
type: "problem",
44
fixable: "code",
@@ -71,4 +71,6 @@ module.exports = {
7171
}
7272
};
7373
},
74-
}
74+
};
75+
76+
export default rule;

opencti-platform/opencti-front/packages/eslint-plugin-custom-rules/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"name": "eslint-plugin-custom-rules",
33
"private": true,
4+
"type": "module",
45
"main": "lib/index.js",
56
"exports": "./lib/index.js",
6-
"dependencies": {
7-
"requireindex": "1.2.0"
8-
},
97
"peerDependencies": {
108
"eslint": ">=7"
119
}

opencti-platform/opencti-front/packages/eslint-plugin-custom-rules/tests/lib/rules/classes-rule.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const rule = require("../../../lib/rules/classes-rule"),
2-
RuleTester = require("eslint").RuleTester;
3-
1+
import rule from '../../../lib/rules/classes-rule';
2+
import { RuleTester } from 'eslint';
3+
import parser from '@typescript-eslint/parser';
44

55
const ruleTester = new RuleTester({
6-
parser: require.resolve('@typescript-eslint/parser'),
6+
parser,
77
parserOptions: {
88
ecmaVersion: 2020,
99
}

0 commit comments

Comments
 (0)