Skip to content

Commit

Permalink
Migrate from CommonJS to ES Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Feb 27, 2022
1 parent 1e1bd78 commit 7cdebd1
Show file tree
Hide file tree
Showing 131 changed files with 1,142 additions and 1,827 deletions.
6 changes: 6 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"reporter": [
"lcov",
"text"
]
}
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": {
"browser": true,
"es6": true,
"es2021": true,
"node": true
},
"extends": [
Expand Down Expand Up @@ -191,7 +191,7 @@
"no-unused-labels": "error",
"no-use-before-define": "off",
"no-var": "error",
"node/file-extension-in-import": ["off"],
"node/file-extension-in-import": ["error", "always"],
"node/no-extraneous-import": "error",
"object-shorthand": "error",
"one-var": [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x, 17.x]

steps:

Expand Down
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extension": ["ts", "tsx"],
"watch-files": ["lib/**/*.ts", "test/**/*.ts"],
"spec": ["test/test-*.ts"],
"loader": ["ts-node/esm"],
"extensions": ["ts", "tsx"]
}
17 changes: 10 additions & 7 deletions doc-gen/gen.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as path from 'path';
import * as fs from 'fs';
import * as path from 'node:path';
import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url';

import { commonTags } from '../lib/common/GenericTagTypes';
import { CombinedTagMapper } from '../lib/common/CombinedTagMapper';
import { commonTags } from '../lib/common/GenericTagTypes.js';
import { CombinedTagMapper } from '../lib/common/CombinedTagMapper.js';

import * as markDown from './MarkDown';
import * as markDown from './MarkDown.js';

interface ITagInfoDict {
[key: string]: { description: string };
}

const combinedTagMapper = new CombinedTagMapper();
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);

function getNativeSourceTags(nativeType: string, commonTag: string): string[] {

Expand All @@ -27,7 +30,7 @@ function getNativeSourceTags(nativeType: string, commonTag: string): string[] {

function write(out: fs.WriteStream) {

const json = fs.readFileSync(path.join(__dirname, 'common.json'));
const json = fs.readFileSync(path.join(dirname, 'common.json'));
const commonDescriptionDict: ITagInfoDict = JSON.parse(json as any);

const table = new markDown.Table();
Expand Down Expand Up @@ -55,7 +58,7 @@ function write(out: fs.WriteStream) {
table.writeTo(out);
}

const txt = fs.createWriteStream(path.join(__dirname, '..', 'doc', 'common_metadata.md'));
const txt = fs.createWriteStream(path.join(dirname, '..', 'doc', 'common_metadata.md'));

txt.write('# Common Metadata\n\n');
txt.write('Common tags, and _native_ to _common_ tag mappings. _n_ indicates the multiplicity.\n');
Expand Down
2 changes: 1 addition & 1 deletion example/typescript/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as mm from '../../lib';
import * as mm from '../../lib.js';
import * as util from 'util';

(async () => {
Expand Down
44 changes: 23 additions & 21 deletions lib/ParserFactory.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { IOptions, IAudioMetadata, ParserType } from './type';
import { ITokenizer } from 'strtok3/lib/core';
import * as FileType from 'file-type/core';
import * as ContentType from 'content-type';
import * as MimeType from 'media-typer';

import { fileTypeFromBuffer } from 'file-type';
import ContentType from 'content-type';
import MimeType from 'media-typer';
import initDebug from 'debug';
import { INativeMetadataCollector, MetadataCollector } from './common/MetadataCollector';
import { AIFFParser } from './aiff/AiffParser';
import { APEv2Parser } from './apev2/APEv2Parser';
import { AsfParser } from './asf/AsfParser';
import { FlacParser } from './flac/FlacParser';
import { MP4Parser } from './mp4/MP4Parser';
import { MpegParser } from './mpeg/MpegParser';
import MusepackParser from './musepack';
import { OggParser } from './ogg/OggParser';
import { WaveParser } from './wav/WaveParser';
import { WavPackParser } from './wavpack/WavPackParser';
import { DsfParser } from './dsf/DsfParser';
import { DsdiffParser } from './dsdiff/DsdiffParser';
import { MatroskaParser } from './matroska/MatroskaParser';
import { Buffer } from 'node:buffer';

import { INativeMetadataCollector, MetadataCollector } from './common/MetadataCollector.js';
import { AIFFParser } from './aiff/AiffParser.js';
import { APEv2Parser } from './apev2/APEv2Parser.js';
import { AsfParser } from './asf/AsfParser.js';
import { FlacParser } from './flac/FlacParser.js';
import { MP4Parser } from './mp4/MP4Parser.js';
import { MpegParser } from './mpeg/MpegParser.js';
import MusepackParser from './musepack/index.js';
import { OggParser } from './ogg/OggParser.js';
import { WaveParser } from './wav/WaveParser.js';
import { WavPackParser } from './wavpack/WavPackParser.js';
import { DsfParser } from './dsf/DsfParser.js';
import { DsdiffParser } from './dsdiff/DsdiffParser.js';
import { MatroskaParser } from './matroska/MatroskaParser.js';

import { IOptions, IAudioMetadata, ParserType } from './type.js';
import { ITokenizer } from 'strtok3/core';

const debug = initDebug('music-metadata:parser:factory');

Expand Down Expand Up @@ -93,7 +95,7 @@ export class ParserFactory {
parserId = this.getParserIdForExtension(tokenizer.fileInfo.path);
}
if (!parserId) {
const guessedType = await FileType.fromBuffer(buf);
const guessedType = await fileTypeFromBuffer(buf);
if (!guessedType) {
throw new Error('Failed to determine audio format');
}
Expand Down
12 changes: 6 additions & 6 deletions lib/aiff/AiffParser.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Token from 'token-types';
import initDebug from 'debug';
import * as strtok3 from 'strtok3/lib/core';
import * as strtok3 from 'strtok3/core';

import { ID3v2Parser } from '../id3v2/ID3v2Parser';
import { FourCcToken } from '../common/FourCC';
import { BasicParser } from '../common/BasicParser';
import { ID3v2Parser } from '../id3v2/ID3v2Parser.js';
import { FourCcToken } from '../common/FourCC.js';
import { BasicParser } from '../common/BasicParser.js';

import * as AiffToken from './AiffToken';
import * as iff from '../iff';
import * as AiffToken from './AiffToken.js';
import * as iff from '../iff/index.js';

const debug = initDebug('music-metadata:parser:aiff');

Expand Down
8 changes: 5 additions & 3 deletions lib/aiff/AiffToken.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as Token from 'token-types';
import { IGetToken } from 'strtok3';
import { Buffer } from 'node:buffer';

import { FourCcToken } from '../common/FourCC.js';
import * as iff from '../iff/index.js';

import {FourCcToken} from '../common/FourCC';
import * as iff from '../iff';
import { IGetToken } from 'strtok3';

/**
* The Common Chunk.
Expand Down
13 changes: 7 additions & 6 deletions lib/apev2/APEv2Parser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import initDebug from 'debug';
import * as strtok3 from 'strtok3/lib/core';
import * as strtok3 from 'strtok3/core';
import { StringType } from 'token-types';
import { Buffer } from 'node:buffer';

import * as util from '../common/Util';
import { IOptions, IRandomReader, IApeHeader } from '../type';
import { INativeMetadataCollector } from '../common/MetadataCollector';
import { BasicParser } from '../common/BasicParser';
import * as util from '../common/Util.js';
import { IOptions, IRandomReader, IApeHeader } from '../type.js';
import { INativeMetadataCollector } from '../common/MetadataCollector.js';
import { BasicParser } from '../common/BasicParser.js';
import {
DataType,
DescriptorParser,
Expand All @@ -15,7 +16,7 @@ import {
IHeader, ITagItemHeader,
TagFooter,
TagItemHeader
} from './APEv2Token';
} from './APEv2Token.js';

const debug = initDebug('music-metadata:parser:APEv2');

Expand Down
4 changes: 2 additions & 2 deletions lib/apev2/APEv2TagMapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {INativeTagMap} from '../common/GenericTagTypes';
import { CaseInsensitiveTagMap } from '../common/CaseInsensitiveTagMap';
import {INativeTagMap} from '../common/GenericTagTypes.js';
import { CaseInsensitiveTagMap } from '../common/CaseInsensitiveTagMap.js';

/**
* ID3v2.2 tag mappings
Expand Down
5 changes: 3 additions & 2 deletions lib/apev2/APEv2Token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Token from 'token-types';
import { IGetToken } from 'strtok3/lib/core';
import { IGetToken } from 'strtok3/core';
import { Buffer } from 'node:buffer';

import { FourCcToken } from '../common/FourCC';
import { FourCcToken } from '../common/FourCC.js';

/**
* APETag versionIndex history / supported formats
Expand Down
15 changes: 8 additions & 7 deletions lib/asf/AsfObject.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// ASF Objects

import { IGetToken, ITokenizer } from 'strtok3/lib/core';

import * as util from '../common/Util';
import { IPicture, ITag } from '../type';
import * as Token from 'token-types';
import GUID from './GUID';
import { AsfUtil } from './AsfUtil';
import { AttachedPictureType } from '../id3v2/ID3v2Token';
import { IGetToken, ITokenizer } from 'strtok3/core';
import { Buffer } from 'node:buffer';

import * as util from '../common/Util.js';
import { IPicture, ITag } from '../type.js';
import GUID from './GUID.js';
import { AsfUtil } from './AsfUtil.js';
import { AttachedPictureType } from '../id3v2/ID3v2Token.js';

/**
* Data Type: Specifies the type of information being stored. The following values are recognized.
Expand Down
8 changes: 4 additions & 4 deletions lib/asf/AsfParser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import initDebug from 'debug';

import { ITag, TrackType } from '../type';
import GUID from './GUID';
import * as AsfObject from './AsfObject';
import { BasicParser } from '../common/BasicParser';
import { ITag, TrackType } from '../type.js';
import GUID from './GUID.js';
import * as AsfObject from './AsfObject.js';
import { BasicParser } from '../common/BasicParser.js';

const debug = initDebug('music-metadata:parser:ASF');
const headerType = 'asf';
Expand Down
6 changes: 3 additions & 3 deletions lib/asf/AsfTagMapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {INativeTagMap} from '../common/GenericTagTypes';
import {CommonTagMapper} from '../common/GenericTagMapper';
import {IRating, ITag} from '../type';
import {INativeTagMap} from '../common/GenericTagTypes.js';
import {CommonTagMapper} from '../common/GenericTagMapper.js';
import {IRating, ITag} from '../type.js';

/**
* ASF Metadata tag mappings.
Expand Down
5 changes: 3 additions & 2 deletions lib/asf/AsfUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Token from 'token-types';
import { Buffer } from 'node:buffer';

import * as util from '../common/Util';
import { DataType } from './AsfObject';
import * as util from '../common/Util.js';
import { DataType } from './AsfObject.js';

export type AttributeParser = (buf: Buffer) => boolean | string | number | bigint | Buffer;

Expand Down
8 changes: 4 additions & 4 deletions lib/common/BasicParser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ITokenizer } from 'strtok3/lib/core';
import { ITokenizer } from 'strtok3/core';

import { ITokenParser } from '../ParserFactory';
import { IOptions, IPrivateOptions } from '../type';
import { INativeMetadataCollector } from './MetadataCollector';
import { ITokenParser } from '../ParserFactory.js';
import { IOptions, IPrivateOptions } from '../type.js';
import { INativeMetadataCollector } from './MetadataCollector.js';

export abstract class BasicParser implements ITokenParser {

Expand Down
4 changes: 2 additions & 2 deletions lib/common/CaseInsensitiveTagMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INativeTagMap, TagType } from './GenericTagTypes';
import { CommonTagMapper } from './GenericTagMapper';
import { INativeTagMap, TagType } from './GenericTagTypes.js';
import { CommonTagMapper } from './GenericTagMapper.js';

export class CaseInsensitiveTagMap extends CommonTagMapper {

Expand Down
26 changes: 13 additions & 13 deletions lib/common/CombinedTagMapper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ID3v1TagMapper } from '../id3v1/ID3v1TagMap';
import { ID3v24TagMapper } from '../id3v2/ID3v24TagMapper';
import { AsfTagMapper } from '../asf/AsfTagMapper';
import { IGenericTag, TagType } from './GenericTagTypes';
import { ID3v22TagMapper } from '../id3v2/ID3v22TagMapper';
import { APEv2TagMapper } from '../apev2/APEv2TagMapper';
import { IGenericTagMapper } from './GenericTagMapper';
import { MP4TagMapper } from '../mp4/MP4TagMapper';
import { VorbisTagMapper } from '../ogg/vorbis/VorbisTagMapper';
import { RiffInfoTagMapper } from '../riff/RiffInfoTagMap';
import { ITag } from '../type';
import { INativeMetadataCollector } from './MetadataCollector';
import { MatroskaTagMapper } from '../matroska/MatroskaTagMapper';
import { ID3v1TagMapper } from '../id3v1/ID3v1TagMap.js';
import { ID3v24TagMapper } from '../id3v2/ID3v24TagMapper.js';
import { AsfTagMapper } from '../asf/AsfTagMapper.js';
import { IGenericTag, TagType } from './GenericTagTypes.js';
import { ID3v22TagMapper } from '../id3v2/ID3v22TagMapper.js';
import { APEv2TagMapper } from '../apev2/APEv2TagMapper.js';
import { IGenericTagMapper } from './GenericTagMapper.js';
import { MP4TagMapper } from '../mp4/MP4TagMapper.js';
import { VorbisTagMapper } from '../ogg/vorbis/VorbisTagMapper.js';
import { RiffInfoTagMapper } from '../riff/RiffInfoTagMap.js';
import { ITag } from '../type.js';
import { INativeMetadataCollector } from './MetadataCollector.js';
import { MatroskaTagMapper } from '../matroska/MatroskaTagMapper.js';

export class CombinedTagMapper {

Expand Down
5 changes: 3 additions & 2 deletions lib/common/FourCC.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as util from './Util';
import { IToken } from 'strtok3/lib/core';
import { IToken } from 'strtok3/core';

import * as util from './Util.js';

const validFourCC = /^[\x21-\x7e©][\x20-\x7e\x00()]{3}/;

Expand Down
8 changes: 4 additions & 4 deletions lib/common/GenericTagMapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as generic from './GenericTagTypes';
import { ITag } from '../type';
import { INativeMetadataCollector, IWarningCollector } from './MetadataCollector';
import * as generic from './GenericTagTypes.js';
import {ITag} from '../type.js';
import { INativeMetadataCollector, IWarningCollector } from './MetadataCollector.js';

export interface IGenericTagMapper {

Expand Down Expand Up @@ -66,7 +66,7 @@ export class CommonTagMapper implements IGenericTagMapper {

/**
* Convert native tag key to common tag key
* @tag Native header tag
* @param tag Native header tag
* @return common tag name (alias)
*/
protected getCommonName(tag: string): generic.GenericTagId {
Expand Down
14 changes: 7 additions & 7 deletions lib/common/MetadataCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
IAudioMetadata, ICommonTagsResult,
IFormat,
INativeTags, IOptions, IQualityInformation, IPicture, ITrackInfo, TrackType
} from '../type';
} from '../type.js';

import initDebug from 'debug';
import { IGenericTag, TagType, isSingleton, isUnique } from './GenericTagTypes';
import { CombinedTagMapper } from './CombinedTagMapper';
import { CommonTagMapper } from './GenericTagMapper';
import { toRatio } from './Util';
import * as FileType from 'file-type/core';
import { IGenericTag, TagType, isSingleton, isUnique } from './GenericTagTypes.js';
import { CombinedTagMapper } from './CombinedTagMapper.js';
import { CommonTagMapper } from './GenericTagMapper.js';
import { toRatio } from './Util.js';
import { fileTypeFromBuffer } from 'file-type';

const debug = initDebug('music-metadata:collector');

Expand Down Expand Up @@ -281,7 +281,7 @@ export class MetadataCollector implements INativeMetadataCollector {
private async postFixPicture(picture: IPicture): Promise<IPicture> {
if (picture.data && picture.data.length > 0) {
if (!picture.format) {
const fileType = await FileType.fromBuffer(picture.data);
const fileType = await fileTypeFromBuffer(picture.data);
if (fileType) {
picture.format = fileType.mime;
} else {
Expand Down
Loading

0 comments on commit 7cdebd1

Please sign in to comment.