Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
]
}
],
"import/extensions": ["error", "never", {
"json": "always",
}],
// Disabled due to https://github.com/import-js/eslint-plugin-import/issues/2104
"import/extensions": [0, "never"],
// This rule conflicts with our convention.
"jest/valid-describe": "off",
// This is not needed for this project.
Expand All @@ -32,20 +31,13 @@
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-member-accessibility": "off",
"import/no-unresolved": ["error", {
ignore: ['estree'],
}],
// This is sad but we have to disable this rule to allow TS to generate
// correct a ESM package.
"import/no-unresolved": "off",
// This rule is annoying and does not add any value.
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/ban-ts-comment": ["error", {
"ts-expect-error": "allow-with-description",
}],
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".ts"]
}
}
}]
}
}
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
export default {
preset: 'ts-jest',
moduleNameMapper: {
// Replace imports ending with `.js` with imports without extensions.
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
};
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
"name": "addons-scanner-utils",
"version": "9.0.0",
"description": "Various addons related helpers to build CLIs.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./io": "./dist/io/index.js",
"./test-helpers": "./dist/test-helpers.js"
},
"files": [
"dist/**/*"
"dist/**"
],
"author": "Mozilla Add-ons Team",
"license": "MPL-2.0",
Expand Down Expand Up @@ -42,12 +48,12 @@
"@types/express": "4.17.17",
"@types/jest": "^29.0.0",
"@types/node": "^18.0.0",
"@types/node-fetch": "^2.6.2",
"@types/node-fetch": "^2.6.3",
"@types/safe-compare": "^1.1.0",
"@types/sinon": "^10.0.0",
"@types/supertest": "^2.0.8",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"body-parser": "1.20.2",
"eslint": "^8.1.0",
"eslint-config-amo": "^5.0.0",
Expand Down
7 changes: 7 additions & 0 deletions src/@types/safe-compare/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// The `@types/safe-compare` package does not declare a module and that breaks
// the type checker...
declare module 'safe-compare' {
function safeCompare(a: string, b: string): boolean;

export default safeCompare;
}
4 changes: 2 additions & 2 deletions src/const.spec.ts → src/constants.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ECMA_VERSION } from './const';
import { ECMA_VERSION } from './constants.js';

describe(__filename, () => {
describe('constants', () => {
it('exports an ECMA_VERSION constant', () => {
expect(ECMA_VERSION).toEqual(13);
});
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
RequestWithFiles,
createApiError,
createExpressApp,
} from './functions';
} from './functions.js';

jest.mock('node-fetch');

describe(__filename, () => {
describe('functions', () => {
describe('createApiError', () => {
it('returns an API error with a message', () => {
const message = 'oops, error';
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './const';
export * from './functions';
export * from './io';
export * from './stdio';
export * from './errors';
export * from './constants.js';
export * from './functions.js';
export * from './io/index.js';
export * from './stdio.js';
export * from './errors.js';
8 changes: 4 additions & 4 deletions src/io/base.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IOBase } from './base';
import { FLAGGED_FILE_MAGIC_NUMBERS_LENGTH } from './const';
import { createFakeStderr } from '../test-helpers';
import { IOBase } from './base.js';
import { FLAGGED_FILE_MAGIC_NUMBERS_LENGTH } from './constants.js';
import { createFakeStderr } from '../test-helpers.js';

describe(__filename, () => {
describe('io/base', () => {
const createIOBase = ({
filePath = 'foo/bar/',
stderr = createFakeStderr(),
Expand Down
7 changes: 5 additions & 2 deletions src/io/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { Readable } from 'stream';

import { oneLine } from 'common-tags';

import { FLAGGED_FILE_MAGIC_NUMBERS_LENGTH, MAX_FILE_SIZE_MB } from './const';
import { Stderr } from '../stdio';
import {
FLAGGED_FILE_MAGIC_NUMBERS_LENGTH,
MAX_FILE_SIZE_MB,
} from './constants.js';
import { Stderr } from '../stdio.js';

type ScanFileFunction = (_path: string, isDirectory: boolean) => boolean;

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions src/io/crx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import defaultFs from 'fs';
import yauzl, { Entry, ZipFile } from 'yauzl';
import realSinon, { SinonSandbox, SinonStub } from 'sinon';

import { defaultParseCRX, Crx } from './crx';
import { Files } from './xpi';
import { DEFLATE_COMPRESSION, NO_COMPRESSION } from './const';
import { createFakeStderr, createFakeZipFile } from '../test-helpers';
import { defaultParseCRX, Crx } from './crx.js';
import { Files } from './xpi.js';
import { DEFLATE_COMPRESSION, NO_COMPRESSION } from './constants.js';
import { createFakeStderr, createFakeZipFile } from '../test-helpers.js';

describe(__filename, () => {
describe('io/crx', () => {
const defaultData = {
compressionMethod: DEFLATE_COMPRESSION,
};
Expand Down
4 changes: 2 additions & 2 deletions src/io/crx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import defaultFs from 'fs';

import yauzl, { ZipFile } from 'yauzl';

import { IOBaseConstructorParams } from './base';
import { Xpi } from './xpi';
import { IOBaseConstructorParams } from './base.js';
import { Xpi } from './xpi.js';

export function defaultParseCRX(buf: Buffer): Buffer {
if (buf.readUInt32BE(0) !== 0x43723234) {
Expand Down
6 changes: 3 additions & 3 deletions src/io/directory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Readable } from 'stream';
import { EventEmitter } from 'events';

import { Directory } from './directory';
import { createFakeStderr, readStringFromStream } from '../test-helpers';
import { Directory } from './directory.js';
import { createFakeStderr, readStringFromStream } from '../test-helpers.js';

describe(__filename, () => {
describe('io/directory', () => {
const fakeFile = {
size: 123,
};
Expand Down
4 changes: 2 additions & 2 deletions src/io/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import FirstChunkStream from 'first-chunk-stream';
import stripBomStream from 'strip-bom-stream';
import { oneLine } from 'common-tags';

import { IOBase, IOBaseConstructorParams } from './base';
import { walkPromise } from './utils';
import { IOBase, IOBaseConstructorParams } from './base.js';
import { walkPromise } from './utils.js';

type Files = { [filename: string]: { size: number } };

Expand Down
10 changes: 5 additions & 5 deletions src/io/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './const';
export * from './crx';
export * from './directory';
export * from './utils';
export * from './xpi';
export * from './constants.js';
export * from './crx.js';
export * from './directory.js';
export * from './utils.js';
export * from './xpi.js';
6 changes: 3 additions & 3 deletions src/io/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WalkPromiseOptions, checkFileExists, walkPromise } from './utils';
import { createFakeFsStats, createFakeStderr } from '../test-helpers';
import { WalkPromiseOptions, checkFileExists, walkPromise } from './utils.js';
import { createFakeFsStats, createFakeStderr } from '../test-helpers.js';

describe(__filename, () => {
describe('io/utils', () => {
describe('walkPromise()', () => {
const _walkPromise = ({
path = 'src/tests/fixtures/io/',
Expand Down
2 changes: 1 addition & 1 deletion src/io/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promisify } from 'util';

import upath from 'upath';

import { Stderr } from '../stdio';
import { Stderr } from '../stdio.js';

export const lstat = promisify(fs.lstat);
export const readFile = promisify(fs.readFile);
Expand Down
10 changes: 5 additions & 5 deletions src/io/xpi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { EventEmitter } from 'events';
import yauzl, { Entry, ZipFile } from 'yauzl';
import realSinon, { SinonSandbox, SinonStub } from 'sinon';

import { DuplicateZipEntryError, InvalidZipFileError } from '../errors';
import { Xpi, Files } from './xpi';
import { DEFLATE_COMPRESSION, NO_COMPRESSION } from './const';
import { DuplicateZipEntryError, InvalidZipFileError } from '../errors.js';
import { Xpi, Files } from './xpi.js';
import { DEFLATE_COMPRESSION, NO_COMPRESSION } from './constants.js';
import {
createFakeStderr,
createFakeZipFile,
readStringFromStream,
} from '../test-helpers';
} from '../test-helpers.js';

describe(__filename, () => {
describe('io/xpi', () => {
const defaultData = {
compressionMethod: DEFLATE_COMPRESSION,
};
Expand Down
4 changes: 2 additions & 2 deletions src/io/xpi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import FirstChunkStream from 'first-chunk-stream';
import stripBomStream from 'strip-bom-stream';
import { oneLine } from 'common-tags';

import { IOBaseConstructorParams, IOBase } from './base';
import { InvalidZipFileError, DuplicateZipEntryError } from '../errors';
import { IOBaseConstructorParams, IOBase } from './base.js';
import { InvalidZipFileError, DuplicateZipEntryError } from '../errors.js';

export type Files = { [filename: string]: Entry };

Expand Down
4 changes: 2 additions & 2 deletions src/stdio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
createConsoleStdout,
createInMemoryStderr,
createInMemoryStdout,
} from './stdio';
} from './stdio.js';

describe(__filename, () => {
describe('stdio', () => {
const createFakeConsole = () => {
return {
...console,
Expand Down
2 changes: 1 addition & 1 deletion src/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from 'stream';

import { ZipFile, RandomAccessReader } from 'yauzl';

import { Stderr, Stdout } from './stdio';
import { Stderr, Stdout } from './stdio.js';

export const createFakeStdout = (): Stdout => {
return {
Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"outDir": "dist",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"module": "nodenext",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"strict": true,
"target": "es2015",
"target": "es2022",
"typeRoots" : ["./node_modules/@types", "./src/@types"]
}
}
Loading