Skip to content

Commit

Permalink
Initial ESM porting effort
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBaryoPX committed Oct 13, 2024
1 parent f91c3d5 commit b5f53b0
Show file tree
Hide file tree
Showing 22 changed files with 393 additions and 520 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

39 changes: 0 additions & 39 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -27,4 +27,4 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npm test
- run: npm test:coverage
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const compat = new FlatCompat({
});

export default [{
ignores: ["**/*tmp*/", "**/*tmp*.*"],
ignores: ["**/*tmp*/", "**/*tmp*.*", "eslint.config.js", "node_modules/"],
}, ...compat.extends("eslint:recommended"), {
languageOptions: {
globals: {
Expand All @@ -23,7 +23,7 @@ export default [{
},

ecmaVersion: "latest",
sourceType: "commonjs",
sourceType: "module",
},

rules: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"lint": "eslint .",
"prepare": "husky",
"test": "node tests/tester.js"
"test": "node --test",
"test:coverage": "node --test --experimental-test-coverage"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/arborist.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {generateCode, generateFlatAST,} = require('./flast');
import {generateCode, generateFlatAST} from './flast.js';

const Arborist = class {
/**
Expand Down Expand Up @@ -169,6 +169,6 @@ const Arborist = class {
}
};

module.exports = {
export {
Arborist,
};
10 changes: 5 additions & 5 deletions src/flast.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {parse} = require('espree');
const {generate, attachComments} = require('escodegen');
const estraverse = require('estraverse');
const {analyze} = require('eslint-scope');
import {parse} from 'espree';
import {generate, attachComments} from 'escodegen';
import estraverse from 'estraverse';
import {analyze} from 'eslint-scope';

const ecmaVersion = 'latest';
const sourceType = 'module';
Expand Down Expand Up @@ -288,7 +288,7 @@ async function generateFlatASTAsync(inputCode, opts = {}) {
return Promise.all(promises).then(() => tree);
}

module.exports = {
export {
estraverse,
extractNodesFromRoot,
generateCode,
Expand Down
10 changes: 4 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module.exports = {
...require('./flast'),
...require('./arborist'),
...require('./types'),
utils: require('./utils'),
};
export * from './flast.js';
export * from './arborist.js';
export * from './types.js';
export * from './utils/index.js';
4 changes: 2 additions & 2 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {Scope} = require('eslint-scope');
import {Scope} from 'eslint-scope';

/**
* @typedef ASTNode
Expand Down Expand Up @@ -88,7 +88,7 @@ class ASTNode {}
*/
class ASTScope extends Scope {}

module.exports = {
export {
ASTNode,
ASTScope,
};
10 changes: 5 additions & 5 deletions src/utils/applyIteratively.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {Arborist} = require('../arborist');
const logger = require('./logger');
const {createHash} = require('node:crypto');
import {Arborist} from '../arborist.js';
import {logger} from './logger.js';
import {createHash} from 'node:crypto';

const generateHash = str => createHash('sha256').update(str).digest('hex');

Expand All @@ -12,7 +12,7 @@ const generateHash = str => createHash('sha256').update(str).digest('hex');
* @param {number?} maxIterations (optional) Stop the loop after this many iterations at most.
* @return {string} The possibly modified script.
*/
function runLoop(script, funcs, maxIterations = 500) {
function applyIteratively(script, funcs, maxIterations = 500) {
let scriptSnapshot = '';
let currentIteration = 0;
let changesCounter = 0;
Expand Down Expand Up @@ -62,4 +62,4 @@ function runLoop(script, funcs, maxIterations = 500) {
return script;
}

module.exports = runLoop;
export {applyIteratively};
8 changes: 4 additions & 4 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
applyIteratively: require('./applyIteratively'),
logger: require('./logger'),
treeModifier: require('./treeModifier'),
export const utils = {
applyIteratively: (await import('./applyIteratively.js')).applyIteratively,
logger: (await import('./logger.js')).logger,
treeModifier: (await import('./treeModifier.js')).treeModifier,
};
4 changes: 2 additions & 2 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const logger = {
setLogLevelDebug() {this.setLogLevel(this.logLevels.DEBUG);},
setLogLevelLog() {this.setLogLevel(this.logLevels.LOG);},
setLogLevelError() {this.setLogLevel(this.logLevels.ERROR);},

setLogFunc(newLogfunc) {
this.logFunc = newLogfunc;
},
};

module.exports = logger;
export {logger};
2 changes: 1 addition & 1 deletion src/utils/treeModifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ function treeModifier(filterFunc, modFunc, funcName) {
return func;
}

module.exports = treeModifier;
export {treeModifier};
155 changes: 0 additions & 155 deletions tests/aboristTests.js

This file was deleted.

Loading

0 comments on commit b5f53b0

Please sign in to comment.