Skip to content

Commit

Permalink
fix: Import files shipped in packages
Browse files Browse the repository at this point in the history
We will now always import files from the `dist` directory, which will make packages work when they are shipped.
  • Loading branch information
fb55 committed Jan 6, 2022
1 parent 96c5205 commit 3d01bf8
Show file tree
Hide file tree
Showing 27 changed files with 70 additions and 65 deletions.
9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -41,7 +41,8 @@
"preversion": "npm test",
"pre-commit": "lint-staged",
"publish": "lerna publish",
"prepare": "husky install"
"prepare": "husky install",
"prepublishOnly": "npm run build"
},
"lint-staged": {
"*.{js,ts}": [
Expand All @@ -53,10 +54,7 @@
]
},
"jest": {
"preset": "ts-jest/presets/js-with-ts-esm",
"extensionsToTreatAsEsm": [
".ts"
],
"preset": "ts-jest/presets/default-esm",
"testEnvironment": "node",
"coverageProvider": "v8",
"globals": {
Expand All @@ -65,6 +63,7 @@
}
},
"moduleNameMapper": {
"^(parse5[^/]*)/dist/(.*?)(?:\\.js)?$": "<rootDir>/packages/$1/lib/$2",
"^(.*)\\.js$": "$1"
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/parse5-html-rewriting-stream/lib/index.ts
@@ -1,6 +1,6 @@
import type { Token, Location } from 'parse5/lib/common/token.js';
import { SAXParser, EndTag, StartTag, Doctype, Text, Comment, SaxToken } from 'parse5-sax-parser/lib/index.js';
import { escapeString } from 'parse5/lib/serializer/index.js';
import type { Token, Location } from 'parse5/dist/common/token.js';
import { SAXParser, EndTag, StartTag, Doctype, Text, Comment, SaxToken } from 'parse5-sax-parser/dist/index.js';
import { escapeString } from 'parse5/dist/serializer/index.js';

/**
* Streaming [SAX](https://en.wikipedia.org/wiki/Simple_API_for_XML)-style HTML rewriter.
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-html-rewriting-stream/package.json
Expand Up @@ -19,7 +19,7 @@
"HTML"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"dependencies": {
"parse5": "^6.0.1",
"parse5-sax-parser": "^6.0.1"
Expand Down
8 changes: 4 additions & 4 deletions packages/parse5-htmlparser2-tree-adapter/lib/index.ts
@@ -1,7 +1,7 @@
import * as doctype from 'parse5/lib/common/doctype.js';
import { DOCUMENT_MODE, NAMESPACES as NS } from 'parse5/lib/common/html.js';
import type { Attribute, ElementLocation } from 'parse5/lib/common/token.js';
import type { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface.js';
import * as doctype from 'parse5/dist/common/doctype.js';
import { DOCUMENT_MODE, NAMESPACES as NS } from 'parse5/dist/common/html.js';
import type { Attribute, ElementLocation } from 'parse5/dist/common/token.js';
import type { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface.js';
import {
Node,
NodeWithChildren,
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-htmlparser2-tree-adapter/package.json
Expand Up @@ -16,7 +16,7 @@
"htmlparser2"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"dependencies": {
"domhandler": "^4.3.0",
"parse5": "^6.0.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/parse5-parser-stream/lib/index.ts
@@ -1,7 +1,7 @@
import { Writable } from 'node:stream';
import { Parser, ParserOptions } from 'parse5/lib/parser/index.js';
import type { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface.js';
import type { DefaultTreeAdapterMap } from 'parse5/lib/tree-adapters/default.js';
import { Parser, ParserOptions } from 'parse5/dist/parser/index.js';
import type { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface.js';
import type { DefaultTreeAdapterMap } from 'parse5/dist/tree-adapters/default.js';

/**
* Streaming HTML parser with scripting support.
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-parser-stream/package.json
Expand Up @@ -16,7 +16,7 @@
"streaming"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"dependencies": {
"parse5": "^6.0.1"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/parse5-parser-stream/test/utils/parse-chunked.ts
@@ -1,5 +1,5 @@
import type { ParserOptions } from 'parse5/lib/parser/index.js';
import type { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface.js';
import type { ParserOptions } from 'parse5/dist/parser/index.js';
import type { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface.js';
import { ParserStream } from '../../lib/index.js';
import { makeChunks } from 'parse5-test-utils/utils/common.js';

Expand Down
8 changes: 4 additions & 4 deletions packages/parse5-plain-text-conversion-stream/lib/index.ts
@@ -1,7 +1,7 @@
import type { ParserOptions } from 'parse5/lib/parser/index.js';
import { ParserStream } from 'parse5-parser-stream/lib/index.js';
import { TAG_ID as $, TAG_NAMES as TN } from 'parse5/lib/common/html.js';
import type { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface';
import type { ParserOptions } from 'parse5/dist/parser/index.js';
import { ParserStream } from 'parse5-parser-stream/dist/index.js';
import { TAG_ID as $, TAG_NAMES as TN } from 'parse5/dist/common/html.js';
import type { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface';

/**
* Converts plain text files into HTML document as required by [HTML specification](https://html.spec.whatwg.org/#read-text).
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-plain-text-conversion-stream/package.json
Expand Up @@ -19,7 +19,7 @@
"plain text"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"dependencies": {
"parse5": "^6.0.1",
"parse5-parse5-stream": "^6.0.1"
Expand Down
@@ -1,5 +1,5 @@
import * as assert from 'node:assert';
import * as parse5 from 'parse5/lib/index.js';
import * as parse5 from 'parse5/dist/index.js';
import { PlainTextConversionStream } from '../lib/index.js';
import { generateTestsForEachTreeAdapter } from 'parse5-test-utils/utils/common.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/parse5-sax-parser/lib/index.ts
@@ -1,5 +1,5 @@
import { Transform } from 'node:stream';
import { Tokenizer } from 'parse5/lib/tokenizer/index.js';
import { Tokenizer } from 'parse5/dist/tokenizer/index.js';
import {
TokenType,
Token,
Expand All @@ -9,7 +9,7 @@ import {
CommentToken,
Attribute,
Location,
} from 'parse5/lib/common/token.js';
} from 'parse5/dist/common/token.js';
import { DevNullStream } from './dev-null-stream.js';
import { ParserFeedbackSimulator } from './parser-feedback-simulator.js';

Expand Down
10 changes: 5 additions & 5 deletions packages/parse5-sax-parser/lib/parser-feedback-simulator.ts
@@ -1,8 +1,8 @@
import { Tokenizer, TokenizerMode } from 'parse5/lib/tokenizer/index.js';
import { TokenType, Token, TagToken } from 'parse5/lib/common/token.js';
import * as foreignContent from 'parse5/lib/common/foreign-content.js';
import * as unicode from 'parse5/lib/common/unicode.js';
import { TAG_ID as $, TAG_NAMES as TN, NAMESPACES as NS, getTagID } from 'parse5/lib/common/html.js';
import { Tokenizer, TokenizerMode } from 'parse5/dist/tokenizer/index.js';
import { TokenType, Token, TagToken } from 'parse5/dist/common/token.js';
import * as foreignContent from 'parse5/dist/common/foreign-content.js';
import * as unicode from 'parse5/dist/common/unicode.js';
import { TAG_ID as $, TAG_NAMES as TN, NAMESPACES as NS, getTagID } from 'parse5/dist/common/html.js';

//ParserFeedbackSimulator
//Simulates adjustment of the Tokenizer which performed by standard parser during tree construction.
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-sax-parser/package.json
Expand Up @@ -17,7 +17,7 @@
"SAX"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"dependencies": {
"parse5": "^6.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-sax-parser/test/location-info.test.ts
Expand Up @@ -2,7 +2,7 @@ import * as assert from 'node:assert';
import { SAXParser } from '../lib/index.js';
import { loadSAXParserTestData } from 'parse5-test-utils/utils/load-sax-parser-test-data.js';
import { writeChunkedToStream } from 'parse5-test-utils/utils/common.js';
import type { Location } from 'parse5/lib/common/token';
import type { Location } from 'parse5/dist/common/token';

function assertLocation({ sourceCodeLocation }: { sourceCodeLocation: Location }): void {
assert.strictEqual(typeof sourceCodeLocation.startLine, 'number');
Expand Down
@@ -1,5 +1,5 @@
import { Tokenizer } from 'parse5/lib/tokenizer/index.js';
import type { Token } from 'parse5/lib/common/token.js';
import { Tokenizer } from 'parse5/dist/tokenizer/index.js';
import type { Token } from 'parse5/dist/common/token.js';
import { generateTokenizationTests } from 'parse5-test-utils/utils/generate-tokenization-tests.js';
import { ParserFeedbackSimulator } from '../lib/parser-feedback-simulator.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/parse5-serializer-stream/lib/index.ts
@@ -1,6 +1,6 @@
import { Readable } from 'node:stream';
import { Serializer, SerializerOptions } from 'parse5/lib/serializer/index.js';
import type { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface';
import { Serializer, SerializerOptions } from 'parse5/dist/serializer/index.js';
import type { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface';

/**
* Streaming AST node to an HTML serializer. A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-serializer-stream/package.json
Expand Up @@ -18,7 +18,7 @@
"serialiser"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"dependencies": {
"parse5": "^6.0.1"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/parse5-test-utils/utils/common.ts
@@ -1,9 +1,9 @@
import { Writable } from 'node:stream';
import * as assert from 'node:assert';
import type { TreeAdapter } from 'parse5/lib/tree-adapters/interface';
import * as defaultTreeAdapter from 'parse5/lib/tree-adapters/default.js';
import * as htmlTreeAdapter from 'parse5-htmlparser2-tree-adapter/lib/index.js';
import type { Location } from 'parse5/lib/common/token';
import type { TreeAdapter } from 'parse5/dist/tree-adapters/interface';
import * as defaultTreeAdapter from 'parse5/dist/tree-adapters/default.js';
import * as htmlTreeAdapter from 'parse5-htmlparser2-tree-adapter/dist/index.js';
import type { Location } from 'parse5/dist/common/token';

// Ensure the default tree adapter matches the expected type.
export const treeAdapters = {
Expand Down
@@ -1,11 +1,11 @@
import { ParserOptions } from 'parse5/lib/parser/index';
import { Location, ElementLocation } from 'parse5/lib/common/token';
import { TreeAdapter, TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface';
import { ParserOptions } from 'parse5/dist/parser/index';
import { Location, ElementLocation } from 'parse5/dist/common/token';
import { TreeAdapter, TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface';
import * as assert from 'node:assert';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { escapeString } from 'parse5/lib/serializer/index.js';
import * as parse5 from 'parse5/lib/index.js';
import { escapeString } from 'parse5/dist/serializer/index.js';
import * as parse5 from 'parse5/dist/index.js';
import {
removeNewLines,
getSubstringByLineCol,
Expand Down
6 changes: 3 additions & 3 deletions packages/parse5-test-utils/utils/generate-parsing-tests.ts
@@ -1,12 +1,12 @@
import { ParserOptions } from 'parse5/lib/parser/index.js';
import { ParserError } from 'parse5/lib/common/error-codes.js';
import { ParserOptions } from 'parse5/dist/parser/index.js';
import { ParserError } from 'parse5/dist/common/error-codes.js';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as assert from 'node:assert';
import { serializeToDatFileFormat } from './serialize-to-dat-file-format.js';
import { generateTestsForEachTreeAdapter } from './common.js';
import { parseDatFile, DatFile } from 'parse5-test-utils/utils/parse-dat-file.js';
import type { TreeAdapter, TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface';
import type { TreeAdapter, TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface';

export interface TreeConstructionTestData<T extends TreeAdapterTypeMap> extends DatFile<T> {
idx: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/parse5-test-utils/utils/generate-serializer-tests.ts
@@ -1,7 +1,7 @@
import * as assert from 'node:assert';
import * as fs from 'node:fs';
import * as parse5 from 'parse5/lib/index.js';
import type { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface.js';
import * as parse5 from 'parse5/dist/index.js';
import type { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface.js';
import { generateTestsForEachTreeAdapter, getStringDiffMsg } from './common.js';

export function generateSerializerTests(
Expand Down
@@ -1,9 +1,9 @@
import * as assert from 'node:assert';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { Tokenizer, TokenizerMode, State as TokenizerState } from 'parse5/lib/tokenizer/index.js';
import { Tokenizer, TokenizerMode, State as TokenizerState } from 'parse5/dist/tokenizer/index.js';
import { makeChunks } from './common.js';
import { TokenType, Token } from 'parse5/lib/common/token.js';
import { TokenType, Token } from 'parse5/dist/common/token.js';

type HtmlLibToken = [string, string | null, ...unknown[]];

Expand Down
6 changes: 3 additions & 3 deletions packages/parse5-test-utils/utils/parse-dat-file.ts
@@ -1,6 +1,6 @@
import { TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface';
import type { TreeAdapter } from 'parse5/lib/tree-adapters/interface';
import { NAMESPACES as NS } from 'parse5/lib/common/html.js';
import { TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface';
import type { TreeAdapter } from 'parse5/dist/tree-adapters/interface';
import { NAMESPACES as NS } from 'parse5/dist/common/html.js';

function createFragmentContext<T extends TreeAdapterTypeMap>(
tagName: string | undefined,
Expand Down
@@ -1,6 +1,6 @@
import { Attribute } from 'parse5/lib/common/token';
import { TreeAdapter, TreeAdapterTypeMap } from 'parse5/lib/tree-adapters/interface';
import { TAG_NAMES as $, NAMESPACES as NS } from 'parse5/lib/common/html.js';
import { Attribute } from 'parse5/dist/common/token';
import { TreeAdapter, TreeAdapterTypeMap } from 'parse5/dist/tree-adapters/interface';
import { TAG_NAMES as $, NAMESPACES as NS } from 'parse5/dist/common/html.js';

function getSerializedTreeIndent(indent: number): string {
return '|'.padEnd(indent + 2, ' ');
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5/package.json
Expand Up @@ -30,7 +30,7 @@
"serialize"
],
"license": "MIT",
"main": "./lib/index.js",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git://github.com/parse5/parse5-fork.git"
Expand Down
10 changes: 8 additions & 2 deletions tsconfig.json
Expand Up @@ -13,8 +13,14 @@
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,

"outDir": "build"
"outDir": "build",
"baseUrl": ".",
"paths": {
"parse5/dist/*": ["packages/parse5/lib/*"],
"parse5-sax-parser/dist/*": ["packages/parse5-sax-parser/lib/*"],
"parse5-htmlparser2-tree-adapter/dist/*": ["packages/parse5-htmlparser2-tree-adapter/lib/*"],
"parse5-parser-stream/dist/*": ["packages/parse5-parser-stream/lib/*"]
}
}
}

0 comments on commit 3d01bf8

Please sign in to comment.