diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd112c9..3797a79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,6 +44,12 @@ jobs: restore-keys: lint-eslint- - run: npm run lint + + - name: Build types + run: npm run build:types + + - name: Check types are up to date + run: if [ -n "$(git status types --porcelain)" ]; then echo "Types are out of date. Update them by running 'npm run build:types'"; git status types --porcelain; exit 1; else echo "Types are up to date"; fi test: strategy: fail-fast: false diff --git a/lib/CachedSource.js b/lib/CachedSource.js index 88c3e84..ff931a3 100644 --- a/lib/CachedSource.js +++ b/lib/CachedSource.js @@ -124,12 +124,10 @@ class CachedSource extends Source { constructor(source, cachedData) { super(); /** - * @private * @type {Source | (() => Source)} */ this._source = source; /** - * @private * @type {undefined | string} */ this._cachedSource = undefined; @@ -139,27 +137,22 @@ class CachedSource extends Source { // branch count roughly in half. if (cachedData) { /** - * @private * @type {boolean | undefined} */ this._cachedSourceType = cachedData.source; /** - * @private * @type {Buffer | undefined} */ this._cachedBuffer = cachedData.buffer; /** - * @private * @type {number | undefined} */ this._cachedSize = cachedData.size; /** - * @private * @type {BufferedMaps} */ this._cachedMaps = cachedData.maps; /** - * @private * @type {(string | Buffer)[] | undefined} */ this._cachedHashUpdate = cachedData.hash; @@ -247,7 +240,6 @@ class CachedSource extends Source { } /** - * @private * @param {BufferEntry} cacheEntry cache entry * @returns {null | RawSourceMap} raw source map */ @@ -262,7 +254,6 @@ class CachedSource extends Source { } /** - * @private * @returns {undefined | string} cached source */ _getCachedSource() { diff --git a/lib/CompatSource.js b/lib/CompatSource.js index 6f132bc..a5f8b1b 100644 --- a/lib/CompatSource.js +++ b/lib/CompatSource.js @@ -43,7 +43,6 @@ class CompatSource extends Source { constructor(sourceLike) { super(); /** - * @private * @type {SourceLike} */ this._sourceLike = sourceLike; diff --git a/lib/ConcatSource.js b/lib/ConcatSource.js index 867302f..2e6c570 100644 --- a/lib/ConcatSource.js +++ b/lib/ConcatSource.js @@ -34,7 +34,6 @@ class ConcatSource extends Source { constructor(...args) { super(); /** - * @private * @type {Child[]} */ this._children = []; @@ -55,7 +54,6 @@ class ConcatSource extends Source { } /** - * @private * @type {boolean} */ this._isOptimized = args.length === 0; diff --git a/lib/OriginalSource.js b/lib/OriginalSource.js index 7e9192d..0fc8e32 100644 --- a/lib/OriginalSource.js +++ b/lib/OriginalSource.js @@ -36,17 +36,14 @@ class OriginalSource extends Source { const isBuffer = Buffer.isBuffer(value); /** - * @private * @type {undefined | string} */ this._value = isBuffer ? undefined : value; /** - * @private * @type {undefined | Buffer} */ this._valueAsBuffer = isBuffer ? value : undefined; /** - * @private * @type {string} */ this._name = name; diff --git a/lib/PrefixSource.js b/lib/PrefixSource.js index 87ec861..bcbbff6 100644 --- a/lib/PrefixSource.js +++ b/lib/PrefixSource.js @@ -56,12 +56,10 @@ class PrefixSource extends Source { constructor(prefix, source) { super(); /** - * @private * @type {string} */ this._prefix = prefix; /** - * @private * @type {Source} */ this._source = diff --git a/lib/RawSource.js b/lib/RawSource.js index f8b1804..347072e 100644 --- a/lib/RawSource.js +++ b/lib/RawSource.js @@ -33,22 +33,18 @@ class RawSource extends Source { const isBuffer = Buffer.isBuffer(value); if (isBuffer) { /** - * @private * @type {boolean} */ this._valueIsBuffer = !convertToString; /** - * @private * @type {undefined | string | Buffer} */ this._value = convertToString ? undefined : value; /** - * @private * @type {undefined | Buffer} */ this._valueAsBuffer = value; /** - * @private * @type {undefined | string} */ this._valueAsString = undefined; diff --git a/lib/ReplaceSource.js b/lib/ReplaceSource.js index c58dc26..503cd73 100644 --- a/lib/ReplaceSource.js +++ b/lib/ReplaceSource.js @@ -92,19 +92,16 @@ class ReplaceSource extends Source { constructor(source, name) { super(); /** - * @private * @type {Source} */ this._source = source; /** - * @private * @type {string | undefined} */ this._name = name; /** @type {Replacement[]} */ this._replacements = []; /** - * @private * @type {boolean} */ this._isSorted = true; diff --git a/lib/SizeOnlySource.js b/lib/SizeOnlySource.js index 1a8214a..9ced558 100644 --- a/lib/SizeOnlySource.js +++ b/lib/SizeOnlySource.js @@ -19,7 +19,6 @@ class SizeOnlySource extends Source { constructor(size) { super(); /** - * @private * @type {number} */ this._size = size; diff --git a/lib/SourceMapSource.js b/lib/SourceMapSource.js index a475a5b..5fab6b6 100644 --- a/lib/SourceMapSource.js +++ b/lib/SourceMapSource.js @@ -45,12 +45,10 @@ class SourceMapSource extends Source { super(); const valueIsBuffer = Buffer.isBuffer(value); /** - * @private * @type {undefined | string} */ this._valueAsString = valueIsBuffer ? undefined : value; /** - * @private * @type {undefined | Buffer} */ this._valueAsBuffer = valueIsBuffer ? value : undefined; @@ -61,18 +59,15 @@ class SourceMapSource extends Source { const sourceMapIsBuffer = Buffer.isBuffer(sourceMap); const sourceMapIsString = typeof sourceMap === "string"; /** - * @private * @type {undefined | RawSourceMap} */ this._sourceMapAsObject = sourceMapIsBuffer || sourceMapIsString ? undefined : sourceMap; /** - * @private * @type {undefined | string} */ this._sourceMapAsString = sourceMapIsString ? sourceMap : undefined; /** - * @private * @type {undefined | Buffer} */ this._sourceMapAsBuffer = sourceMapIsBuffer ? sourceMap : undefined; @@ -90,7 +85,6 @@ class SourceMapSource extends Source { const innerSourceMapIsBuffer = Buffer.isBuffer(innerSourceMap); const innerSourceMapIsString = typeof innerSourceMap === "string"; /** - * @private * @type {undefined | RawSourceMap} */ @@ -99,14 +93,12 @@ class SourceMapSource extends Source { ? undefined : innerSourceMap || undefined; /** - * @private * @type {undefined | string} */ this._innerSourceMapAsString = innerSourceMapIsString ? innerSourceMap : undefined; /** - * @private * @type {undefined | Buffer} */ this._innerSourceMapAsBuffer = innerSourceMapIsBuffer @@ -178,7 +170,6 @@ class SourceMapSource extends Source { } /** - * @private * @returns {undefined | Buffer} buffer */ _originalSourceBuffer() { @@ -232,7 +223,6 @@ class SourceMapSource extends Source { } /** - * @private * @returns {string} result */ _innerSourceMapString() { diff --git a/package-lock.json b/package-lock.json index 9d2f9e4..28c05a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@changesets/get-github-info": "^1.0.1", "@codspeed/core": "^5.5.0", "@types/jest": "^30.0.0", + "del-cli": "^7.0.0", "eslint": "^9.39.5", "eslint-config-webpack": "^4.14.0", "jest": "^30.5.2", @@ -21,7 +22,6 @@ "source-map": "^0.8.0", "sourcemap-validator": "^2.1.0", "tinybench": "^6.0.0", - "tooling": "webpack/tooling#v1.28.3", "typescript": "^6.0.2", "webpack": "^5.107.2" }, @@ -29,24 +29,6 @@ "node": ">=10.13.0" } }, - "node_modules/@apidevtools/json-schema-ref-parser": { - "version": "11.9.3", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.9.3.tgz", - "integrity": "sha512-60vepv88RwcJtSHrD6MjIL6Ta3SOYbgfnkHb+ppAVK+o9mXprRtulx7VlRl3lN3bbvysAfCS7WMVfhUYemB0IQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@jsdevtools/ono": "^7.1.3", - "@types/json-schema": "^7.0.15", - "js-yaml": "^4.1.0" - }, - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://github.com/sponsors/philsturgeon" - } - }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", @@ -2019,13 +2001,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jsdevtools/ono": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", - "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==", - "dev": true, - "license": "MIT" - }, "node_modules/@manypkg/find-root": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@manypkg/find-root/-/find-root-3.1.0.tgz", @@ -2090,6 +2065,44 @@ "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.4" } }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/@parcel/watcher": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.6.0.tgz", @@ -2393,6 +2406,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@sindresorhus/merge-streams": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-2.3.0.tgz", + "integrity": "sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@sinonjs/commons": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", @@ -2576,13 +2602,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/lodash": { - "version": "4.17.24", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.24.tgz", - "integrity": "sha512-gIW7lQLZbue7lRSWEFql49QJJWThrTFFeIMJdp3eH4tKoxm1OvEPg02rm4wCCSHS0cL3/Fizimb35b7k8atwsQ==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/mdast": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", @@ -3332,13 +3351,6 @@ "dev": true, "license": "Apache-2.0" }, - "node_modules/@yarnpkg/lockfile": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", - "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==", - "dev": true, - "license": "BSD-2-Clause" - }, "node_modules/acorn": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", @@ -3864,6 +3876,19 @@ "concat-map": "0.0.1" } }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/browserslist": { "version": "4.28.8", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.8.tgz", @@ -4141,18 +4166,6 @@ "node": ">=0.8.0" } }, - "node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -4221,13 +4234,6 @@ "node": ">= 12.0.0" } }, - "node_modules/commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", - "dev": true, - "license": "MIT" - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -4432,6 +4438,63 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/del": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/del/-/del-8.0.1.tgz", + "integrity": "sha512-gPqh0mKTPvaUZGAuHbrBUYKZWBNAeHG7TU3QH5EhVwPMyKvmfJaNXhcD2jTcXsJRRcffuho4vaYweu80dRrMGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "globby": "^14.0.2", + "is-glob": "^4.0.3", + "is-path-cwd": "^3.0.0", + "is-path-inside": "^4.0.0", + "p-map": "^7.0.2", + "presentable-error": "^0.0.1", + "slash": "^5.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/del-cli": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/del-cli/-/del-cli-7.0.0.tgz", + "integrity": "sha512-fRl4pWJYu9WFQH8jXdQUYvcD0IMtij9WEc7qmB7xOyJEweNJNuE7iKmqNeoOT1DbBUjtRjxlw8Y63qKBI/NQ1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "del": "^8.0.1", + "meow": "^14.0.0", + "presentable-error": "^0.0.1" + }, + "bin": { + "del": "cli.js", + "del-cli": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/del/node_modules/slash": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz", + "integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -5540,6 +5603,36 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/fast-glob": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.8" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -5598,6 +5691,16 @@ "fast-string-width": "^3.0.2" } }, + "node_modules/fastq": { + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz", + "integrity": "sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==", + "dev": true, + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, "node_modules/fault": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fault/-/fault-2.0.1.tgz", @@ -5653,6 +5756,19 @@ "node": ">=16.0.0" } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -5797,13 +5913,6 @@ "node": ">=0.4.x" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true, - "license": "ISC" - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -5985,28 +6094,6 @@ "dev": true, "license": "ISC" }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", - "dev": true, - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -6050,6 +6137,50 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/globby": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.1.0.tgz", + "integrity": "sha512-0Ia46fDOaT7k4og1PDW4YbodWWr3scS2vAr2lTbsplOt2WkKp0vQbkI9wKis/T5LV/dqPjO3bpS/z6GTJB82LA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sindresorhus/merge-streams": "^2.1.0", + "fast-glob": "^3.3.3", + "ignore": "^7.0.3", + "path-type": "^6.0.0", + "slash": "^5.1.0", + "unicorn-magic": "^0.3.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/globby/node_modules/ignore": { + "version": "7.0.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.10.tgz", + "integrity": "sha512-HpbUakT7xp5miBUywCHf36ZEuAJNklBJDDsGpUIjMzOSmM8ELSfA9Sa/QDPeNeqeoN31u+UTCkL4klCOVvRm4Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/globby/node_modules/slash": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz", + "integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/globrex": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", @@ -6337,25 +6468,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "dev": true, - "license": "ISC", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true, - "license": "ISC" - }, "node_modules/internal-slot": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.1.0.tgz", @@ -6634,6 +6746,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/is-number-object": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.1.1.tgz", @@ -6651,6 +6773,32 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-path-cwd": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-3.0.0.tgz", + "integrity": "sha512-kyiNFFLU0Ampr6SDZitD/DwUo4Zs1nSdnygUBqsu3LooL00Qvb5j+UnvApUn/TTj1J3OuE6BTdQ5rudKmU2ZaA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-path-inside": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-4.0.0.tgz", + "integrity": "sha512-lJJV/5dYS+RcL8uQdBDW9c9uWFLLBNRyFhnAKXw5tVqLlKZ4RMGZKv+YQ/IA3OhD+RpbJa1LLFM1FQPGyIXvOA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-plain-obj": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-4.1.0.tgz", @@ -7799,30 +7947,6 @@ "dev": true, "license": "MIT" }, - "node_modules/json-schema-to-typescript": { - "version": "15.0.4", - "resolved": "https://registry.npmjs.org/json-schema-to-typescript/-/json-schema-to-typescript-15.0.4.tgz", - "integrity": "sha512-Su9oK8DR4xCmDsLlyvadkXzX6+GGXJpbhwoLtOGArAG61dvbW4YQmSEno2y66ahpIdmLMg6YUf/QHLgiwvkrHQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@apidevtools/json-schema-ref-parser": "^11.5.5", - "@types/json-schema": "^7.0.15", - "@types/lodash": "^4.17.7", - "is-glob": "^4.0.3", - "js-yaml": "^4.1.0", - "lodash": "^4.17.21", - "minimist": "^1.2.8", - "prettier": "^3.2.5", - "tinyglobby": "^0.2.9" - }, - "bin": { - "json2ts": "dist/src/cli.js" - }, - "engines": { - "node": ">=16.0.0" - } - }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -7999,13 +8123,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash": { - "version": "4.18.1", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", - "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", - "dev": true, - "license": "MIT" - }, "node_modules/lodash._reinterpolate": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz", @@ -8385,6 +8502,19 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/meow": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/meow/-/meow-14.1.0.tgz", + "integrity": "sha512-EDYo6VlmtnumlcBCbh1gLJ//9jvM/ndXHfVXIFrZVr6fGcwTUyCTFNTLCKuY3ffbK8L/+3Mzqnd58RojiZqHVw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -8392,6 +8522,16 @@ "dev": true, "license": "MIT" }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, "node_modules/micromark": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.2.tgz", @@ -9020,6 +9160,33 @@ ], "license": "MIT" }, + "node_modules/micromatch": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -9395,16 +9562,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, "node_modules/onetime": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", @@ -9489,6 +9646,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-map": { + "version": "7.0.8", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-7.0.8.tgz", + "integrity": "sha512-MitaVsCuCFIvOLLPIU7NnfrZvS9H9h7kwMUkDo+T2pEISaJD48IV9S8iIdXB7PsvvdxyYcsSTTrr90XKsbulNw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -9572,16 +9742,6 @@ "node": ">=8" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -9626,6 +9786,19 @@ "node": "20 || >=22" } }, + "node_modules/path-type": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-6.0.0.tgz", + "integrity": "sha512-Vj7sf++t5pBD637NSfkxpHSMfWaeig5+DKWLhcqIYx6mWQz5hdJTGDVMQiJcw1ZYkhs7AazKDGpRVji1LJCZUQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -9755,6 +9928,19 @@ "node": ">= 0.8.0" } }, + "node_modules/presentable-error": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/presentable-error/-/presentable-error-0.0.1.tgz", + "integrity": "sha512-E6rsNU1QNJgB3sjj7OANinGncFKuK+164sLXw1/CqBjj/EkXSoSdHCtWQGBNlREIGLnL7IEUEGa08YFVUbrhVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/prettier": { "version": "3.9.9", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.9.tgz", @@ -9879,6 +10065,27 @@ ], "license": "MIT" }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", @@ -10043,6 +10250,41 @@ "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" } }, + "node_modules/reusify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", + "dev": true, + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, "node_modules/safe-array-concat": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.3.tgz", @@ -11002,6 +11244,19 @@ "url": "https://github.com/sponsors/SuperchupuDev" } }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/to-valid-identifier": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-valid-identifier/-/to-valid-identifier-1.0.0.tgz", @@ -11019,49 +11274,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/tooling": { - "version": "1.28.3", - "resolved": "git+ssh://git@github.com/webpack/tooling.git#d42bb245dd2ba96025b19342973859cdbde5bd53", - "dev": true, - "license": "MIT", - "dependencies": { - "@yarnpkg/lockfile": "^1.1.0", - "ajv": "^8.18.0", - "commondir": "^1.0.1", - "glob": "^7.1.6", - "json-schema-to-typescript": "^15.0.4", - "terser": "^5.32.0", - "yargs": "^16.1.1" - }, - "peerDependencies": { - "prettier": "*", - "typescript": "*" - } - }, - "node_modules/tooling/node_modules/ajv": { - "version": "8.18.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", - "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/tooling/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "license": "MIT" - }, "node_modules/ts-api-utils": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz", @@ -11297,6 +11509,19 @@ "dev": true, "license": "MIT" }, + "node_modules/unicorn-magic": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.3.0.tgz", + "integrity": "sha512-+QBBXBCvifc56fsbuxZQ6Sic3wqqc3WWaqxs58gvJrcOuN83HGTCwz3oS5phzU9LthRNE9VrJCFCLUgHeeFnfA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/unist-util-is": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", @@ -11691,13 +11916,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true, - "license": "ISC" - }, "node_modules/write-file-atomic": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-5.0.1.tgz", @@ -11758,35 +11976,6 @@ "url": "https://github.com/sponsors/eemeli" } }, - "node_modules/yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "dev": true, - "license": "MIT", - "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/yargs-parser": { - "version": "20.2.9", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", - "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=10" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 601969b..17cf58a 100644 --- a/package.json +++ b/package.json @@ -15,19 +15,18 @@ "author": "Tobias Koppers @sokra", "main": "lib/index.js", "types": "types.d.ts", - "files": ["lib/", "types.d.ts"], + "files": ["lib/", "types/", "types.d.ts"], "scripts": { - "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run lint:special", + "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test", "lint:code": "eslint --cache .", - "lint:special": "node node_modules/tooling/inherit-types && node node_modules/tooling/format-file-header && node node_modules/tooling/generate-types", "lint:types": "tsc", "lint:types-test": "tsc -p tsconfig.types.test.json", "fmt": "npm run fmt:base -- --loglevel warn --write", "fmt:check": "npm run fmt:base -- --check", "fmt:base": "prettier --cache --ignore-unknown .", - "fix": "npm run fix:code && npm run fix:special", + "fix": "npm run fix:code && npm run build:types", "fix:code": "npm run lint:code -- --fix", - "fix:special": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/generate-types --write", + "build:types": "del-cli types && tsc -p tsconfig.types.json && prettier --log-level warn --write types", "pretest": "npm run lint", "test": "jest", "test:coverage": "jest --coverage", @@ -41,6 +40,7 @@ "@changesets/get-github-info": "^1.0.1", "@codspeed/core": "^5.5.0", "@types/jest": "^30.0.0", + "del-cli": "^7.0.0", "eslint": "^9.39.5", "eslint-config-webpack": "^4.14.0", "jest": "^30.5.2", @@ -49,7 +49,6 @@ "source-map": "^0.8.0", "sourcemap-validator": "^2.1.0", "tinybench": "^6.0.0", - "tooling": "webpack/tooling#v1.28.3", "typescript": "^6.0.2", "webpack": "^5.107.2" }, diff --git a/test/ReplaceSource.js b/test/ReplaceSource.js index 4fd7ae3..97be1ab 100644 --- a/test/ReplaceSource.js +++ b/test/ReplaceSource.js @@ -56,7 +56,6 @@ describe("replaceSource", () => { columns: false, }); - // @ts-expect-error for tests expect(originalSource).toEqual(source._source); expect(originalText).toBe( "Hello World!\n{}\nLine 3\nLine 4\nLine 5\nLast\nLine", diff --git a/tsconfig.types.json b/tsconfig.types.json index 1c66acf..97318fc 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -1,3 +1,11 @@ { - "extends": "./tsconfig" + "extends": "./tsconfig", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "emitDeclarationOnly": true, + "rootDir": "./lib", + "outDir": "./types" + }, + "include": ["lib/**/*.js"] } diff --git a/tsconfig.types.test.json b/tsconfig.types.test.json index 50d014a..dc74368 100644 --- a/tsconfig.types.test.json +++ b/tsconfig.types.test.json @@ -7,5 +7,5 @@ "strictNullChecks": true, "types": ["node", "jest"] }, - "include": ["test/*.js"] + "include": ["test/*.js", "types.d.ts"] } diff --git a/types.d.ts b/types.d.ts index 4427cff..c6c8fa2 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,478 +1,50 @@ /* - * This file was automatically generated. - * DO NOT MODIFY BY HAND. - * Run `yarn fix:special` to update + * Public type entry point of `webpack-sources`. + * + * The declarations under `types/` are generated from the JSDoc in `lib/` by + * `npm run build:types`; don't edit them by hand. This file re-exports them in + * the package's public shape: every class is available as both a value and a + * type, next to the public helper types. + * + * TODO: remove this file in the next major release and point `types` in + * `package.json` at the generated `types/index.d.ts`. That requires the + * exports in `lib/index.js` to be typed so the classes are exported as types + * too (e.g. `Source` usable in `let source: Source`), which is a breaking + * change for the shape of the public types. */ -import { Buffer } from "buffer"; +import CachedSource = require("./types/CachedSource"); +import CompatSource = require("./types/CompatSource"); +import ConcatSource = require("./types/ConcatSource"); +import OriginalSource = require("./types/OriginalSource"); +import PrefixSource = require("./types/PrefixSource"); +import RawSource = require("./types/RawSource"); +import ReplaceSource = require("./types/ReplaceSource"); +import SizeOnlySource = require("./types/SizeOnlySource"); +import Source = require("./types/Source"); +import SourceMapSource = require("./types/SourceMapSource"); +import GetGeneratedSourceInfo = require("./types/helpers/getGeneratedSourceInfo"); +import StreamChunks = require("./types/helpers/streamChunks"); +import StringBufferUtils = require("./types/helpers/stringBufferUtils"); -declare interface BufferEntry { - map?: null | RawSourceMap; - bufferedMap?: null | BufferedMap; -} -declare interface BufferedMap { - /** - * version - */ - version: number; - - /** - * sources - */ - sources: string[]; - - /** - * name - */ - names: string[]; - - /** - * source root - */ - sourceRoot?: string; - - /** - * sources content - */ - sourcesContent?: ("" | Buffer)[]; - - /** - * mappings - */ - mappings?: Buffer; - - /** - * file - */ - file: string; -} -declare interface CachedData { - /** - * source - */ - source?: boolean; - - /** - * buffer - */ - buffer: Buffer; - - /** - * size - */ - size?: number; - - /** - * maps - */ - maps: Map; - - /** - * hash - */ - hash?: (string | Buffer)[]; -} -declare class CachedSource extends Source { - constructor(source: Source | (() => Source), cachedData?: CachedData); - getCachedData(): CachedData; - originalLazy(): Source | (() => Source); - original(): Source; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; -} -declare interface ClearCacheOptions { - /** - * drop cached source maps (default `true`) - */ - maps?: boolean; - - /** - * drop cached source/buffer copies (default `true`) - */ - source?: boolean; - - /** - * drop the parsed object form of cached source maps on `SourceMapSource` instances (default `false` — re-parsing JSON is significantly more expensive than `toString`). Only takes effect when a serialized form (buffer or string) is also retained, so the data remains recoverable. - */ - parsedMap?: boolean; -} -declare class CompatSource extends Source { - constructor(sourceLike: SourceLike); - static from(sourceLike: SourceLike): Source; -} -declare class ConcatSource extends Source { - constructor(...args: ConcatSourceChild[]); - getChildren(): Source[]; - add(item: ConcatSourceChild): void; - addAllSkipOptimizing(items: ConcatSourceChild[]): void; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; -} -type ConcatSourceChild = string | Source | SourceLike; -declare interface GeneratedSourceInfo { - /** - * generated line - */ - generatedLine?: number; - - /** - * generated column - */ - generatedColumn?: number; - - /** - * source - */ - source?: string; -} -declare interface HashLike { - /** - * make hash update - */ - update: (data: string | Buffer, inputEncoding?: string) => HashLike; - - /** - * get hash digest - */ - digest: (encoding?: string) => string | Buffer; -} -declare interface MapOptions { - /** - * need columns? - */ - columns?: boolean; - - /** - * is module - */ - module?: boolean; -} -declare class OriginalSource extends Source { - constructor(value: string | Buffer, name: string); - getName(): string; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - _onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; -} -declare class PrefixSource extends Source { - constructor(prefix: string, source: string | Source | Buffer); - getPrefix(): string; - original(): Source; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; -} -declare class RawSource extends Source { - constructor(value: string | Buffer, convertToString?: boolean); - isBuffer(): boolean; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; -} -declare interface RawSourceMap { - /** - * version - */ - version: number; - - /** - * sources - */ - sources: string[]; - - /** - * names - */ - names: string[]; - - /** - * source root - */ - sourceRoot?: string; - - /** - * sources content - */ - sourcesContent?: string[]; - - /** - * mappings - */ - mappings: string; - - /** - * file - */ - file: string; - - /** - * debug id - */ - debugId?: string; - - /** - * ignore list - */ - ignoreList?: number[]; -} -declare class ReplaceSource extends Source { - constructor(source: Source, name?: string); - getName(): undefined | string; - getReplacements(): Replacement[]; - replace(start: number, end: number, newValue: string, name?: string): void; - insert(pos: number, newValue: string, name?: string): void; - original(): Source; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; - static Replacement: typeof Replacement; -} -declare class Replacement { - constructor(start: number, end: number, content: string, name?: string); - start: number; - end: number; - content: string; - name?: string; - index?: number; -} -declare class SizeOnlySource extends Source { - constructor(size: number); -} -declare class Source { - constructor(); - source(): SourceValue; - buffer(): Buffer; - buffers(): Buffer[]; - size(): number; - map(options?: MapOptions): null | RawSourceMap; - sourceAndMap(options?: MapOptions): SourceAndMap; - updateHash(hash: HashLike): void; - - /** - * Release cached data held by this source. clearCache is a memory - * hint: it never affects correctness or output, only how expensive - * the next read is. Subclasses override; the base is a no-op so - * every Source supports the call. Composite sources always recurse - * into wrapped sources. When the same child is reachable via several - * parents (e.g. modules shared across webpack chunks), pass a shared - * `visited` WeakSet so each subtree is walked at most once. - * Not safe to call concurrently with source/map/sourceAndMap/ - * streamChunks/updateHash on the same instance. - */ - clearCache(options?: ClearCacheOptions, visited?: WeakSet): void; -} -declare interface SourceAndMap { - /** - * source - */ - source: SourceValue; - - /** - * map - */ - map: null | RawSourceMap; -} -declare interface SourceLike { - /** - * source - */ - source: () => SourceValue; - - /** - * buffer - */ - buffer?: () => Buffer; - - /** - * buffers - */ - buffers?: () => Buffer[]; - - /** - * size - */ - size?: () => number; - - /** - * map - */ - map?: (options?: MapOptions) => null | RawSourceMap; - - /** - * source and map - */ - sourceAndMap?: (options?: MapOptions) => SourceAndMap; - - /** - * hash updater - */ - updateHash?: (hash: HashLike) => void; - - /** - * clear cache - */ - clearCache?: (options?: ClearCacheOptions, visited?: WeakSet) => void; -} -declare class SourceMapSource extends Source { - constructor( - value: string | Buffer, - name: string, - sourceMap?: string | RawSourceMap | Buffer, - originalSource?: string | Buffer, - innerSourceMap?: null | string | RawSourceMap | Buffer, - removeOriginalSource?: boolean, - ); - getArgsAsBuffers(): [ - Buffer, - string, - Buffer, - undefined | Buffer, - undefined | Buffer, - undefined | boolean, - ]; - streamChunks( - options: StreamChunksOptions, - onChunk: ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void, - onSource: ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void, - onName: (nameIndex: number, name: string) => void, - ): GeneratedSourceInfo; -} -type SourceValue = string | Buffer; -declare interface StreamChunksOptions { - source?: boolean; - finalSource?: boolean; - columns?: boolean; -} declare namespace exports { export namespace util { - export namespace stringBufferUtils { - export let disableDualStringBufferCaching: () => void; - export let enableDualStringBufferCaching: () => void; - export let enterStringInterningRange: () => void; - export let exitStringInterningRange: () => void; - export let internString: (str: string) => string; - export let isDualStringBufferCachingEnabled: () => boolean; - } + export import stringBufferUtils = StringBufferUtils; } - export type OnChunk = ( - chunk: undefined | string, - generatedLine: number, - generatedColumn: number, - sourceIndex: number, - originalLine: number, - originalColumn: number, - nameIndex: number, - ) => void; - export type OnName = (nameIndex: number, name: string) => void; - export type OnSource = ( - sourceIndex: number, - source: null | string, - sourceContent?: string, - ) => void; + export type OnChunk = StreamChunks.OnChunk; + export type OnName = StreamChunks.OnName; + export type OnSource = StreamChunks.OnSource; + export type CachedData = CachedSource.CachedData; + export type SourceLike = CompatSource.SourceLike; + export type ConcatSourceChild = ConcatSource.Child; + export import Replacement = ReplaceSource.Replacement; + export type HashLike = Source.HashLike; + export type MapOptions = Source.MapOptions; + export type RawSourceMap = Source.RawSourceMap; + export type SourceAndMap = Source.SourceAndMap; + export type SourceValue = Source.SourceValue; + export type GeneratedSourceInfo = GetGeneratedSourceInfo.GeneratedSourceInfo; + export type StreamChunksOptions = StreamChunks.Options; export { Source, RawSource, @@ -484,17 +56,6 @@ declare namespace exports { PrefixSource, SizeOnlySource, CompatSource, - CachedData, - SourceLike, - ConcatSourceChild, - Replacement, - HashLike, - MapOptions, - RawSourceMap, - SourceAndMap, - SourceValue, - GeneratedSourceInfo, - StreamChunksOptions, }; } diff --git a/types/CachedSource.d.ts b/types/CachedSource.d.ts new file mode 100644 index 0000000..d6075b5 --- /dev/null +++ b/types/CachedSource.d.ts @@ -0,0 +1,165 @@ +export = CachedSource; +/** + * @typedef {object} CachedData + * @property {boolean=} source source + * @property {Buffer} buffer buffer + * @property {number=} size size + * @property {BufferedMaps} maps maps + * @property {(string | Buffer)[]=} hash hash + */ +declare class CachedSource extends Source { + /** + * @param {Source | (() => Source)} source source + * @param {CachedData=} cachedData cached data + */ + constructor( + source: Source | (() => Source), + cachedData?: CachedData | undefined, + ); + /** + * @type {Source | (() => Source)} + */ + _source: Source | (() => Source); + /** + * @type {undefined | string} + */ + _cachedSource: undefined | string; + /** + * @type {boolean | undefined} + */ + _cachedSourceType: boolean | undefined; + /** + * @type {Buffer | undefined} + */ + _cachedBuffer: Buffer | undefined; + /** + * @type {number | undefined} + */ + _cachedSize: number | undefined; + /** + * @type {BufferedMaps} + */ + _cachedMaps: BufferedMaps; + /** + * @type {(string | Buffer)[] | undefined} + */ + _cachedHashUpdate: (string | Buffer)[] | undefined; + /** + * @returns {CachedData} cached data + */ + getCachedData(): CachedData; + originalLazy(): Source | (() => Source); + original(): Source; + /** + * @param {BufferEntry} cacheEntry cache entry + * @returns {null | RawSourceMap} raw source map + */ + _getMapFromCacheEntry(cacheEntry: BufferEntry): null | RawSourceMap; + /** + * @returns {undefined | string} cached source + */ + _getCachedSource(): undefined | string; + _cachedBuffers: Buffer[] | undefined; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + ): GeneratedSourceInfo; +} +declare namespace CachedSource { + export { + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + BufferedMap, + BufferEntry, + BufferedMaps, + CachedData, + }; +} +import Source = require("./Source"); +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; +type BufferedMap = { + /** + * version + */ + version: number; + /** + * sources + */ + sources: string[]; + /** + * name + */ + names: string[]; + /** + * source root + */ + sourceRoot?: string | undefined; + /** + * sources content + */ + sourcesContent?: (Buffer | "")[] | undefined; + /** + * mappings + */ + mappings?: Buffer | undefined; + /** + * file + */ + file: string; +}; +type BufferEntry = { + map?: null | RawSourceMap; + bufferedMap?: null | BufferedMap; +}; +type BufferedMaps = Map; +type CachedData = { + /** + * source + */ + source?: boolean | undefined; + /** + * buffer + */ + buffer: Buffer; + /** + * size + */ + size?: number | undefined; + /** + * maps + */ + maps: BufferedMaps; + /** + * hash + */ + hash?: (string | Buffer)[] | undefined; +}; diff --git a/types/CompatSource.d.ts b/types/CompatSource.d.ts new file mode 100644 index 0000000..a30913b --- /dev/null +++ b/types/CompatSource.d.ts @@ -0,0 +1,87 @@ +export = CompatSource; +/** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */ +/** @typedef {import("./Source").HashLike} HashLike */ +/** @typedef {import("./Source").MapOptions} MapOptions */ +/** @typedef {import("./Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./Source").SourceAndMap} SourceAndMap */ +/** @typedef {import("./Source").SourceValue} SourceValue */ +/** + * @typedef {object} SourceLike + * @property {() => SourceValue} source source + * @property {(() => Buffer)=} buffer buffer + * @property {(() => Buffer[])=} buffers buffers + * @property {(() => number)=} size size + * @property {((options?: MapOptions) => RawSourceMap | null)=} map map + * @property {((options?: MapOptions) => SourceAndMap)=} sourceAndMap source and map + * @property {((hash: HashLike) => void)=} updateHash hash updater + * @property {((options?: ClearCacheOptions, visited?: WeakSet) => void)=} clearCache clear cache + */ +declare class CompatSource extends Source { + /** + * @param {SourceLike} sourceLike source like + * @returns {Source} source + */ + static from(sourceLike: SourceLike): Source; + /** + * @param {SourceLike} sourceLike source like + */ + constructor(sourceLike: SourceLike); + /** + * @type {SourceLike} + */ + _sourceLike: SourceLike; +} +declare namespace CompatSource { + export { + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + SourceLike, + }; +} +import Source = require("./Source"); +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type SourceLike = { + /** + * source + */ + source: () => SourceValue; + /** + * buffer + */ + buffer?: (() => Buffer) | undefined; + /** + * buffers + */ + buffers?: (() => Buffer[]) | undefined; + /** + * size + */ + size?: (() => number) | undefined; + /** + * map + */ + map?: ((options?: MapOptions) => RawSourceMap | null) | undefined; + /** + * source and map + */ + sourceAndMap?: ((options?: MapOptions) => SourceAndMap) | undefined; + /** + * hash updater + */ + updateHash?: ((hash: HashLike) => void) | undefined; + /** + * clear cache + */ + clearCache?: + | ((options?: ClearCacheOptions, visited?: WeakSet) => void) + | undefined; +}; diff --git a/types/ConcatSource.d.ts b/types/ConcatSource.d.ts new file mode 100644 index 0000000..bdb93c8 --- /dev/null +++ b/types/ConcatSource.d.ts @@ -0,0 +1,75 @@ +export = ConcatSource; +declare class ConcatSource extends Source { + /** + * @param {Child[]} args children + */ + constructor(...args: Child[]); + /** + * @type {Child[]} + */ + _children: Child[]; + /** + * @type {boolean} + */ + _isOptimized: boolean; + /** + * @returns {Source[]} children + */ + getChildren(): Source[]; + /** + * @param {Child} item item + * @returns {void} + */ + add(item: Child): void; + /** + * @param {Child[]} items items + * @returns {void} + */ + addAllSkipOptimizing(items: Child[]): void; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + ): GeneratedSourceInfo; + _optimize(): void; +} +declare namespace ConcatSource { + export { + SourceLike, + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + Child, + }; +} +import Source = require("./Source"); +type SourceLike = import("./CompatSource").SourceLike; +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; +type Child = string | Source | SourceLike; diff --git a/types/OriginalSource.d.ts b/types/OriginalSource.d.ts new file mode 100644 index 0000000..20cb222 --- /dev/null +++ b/types/OriginalSource.d.ts @@ -0,0 +1,74 @@ +export = OriginalSource; +/** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */ +/** @typedef {import("./Source").HashLike} HashLike */ +/** @typedef {import("./Source").MapOptions} MapOptions */ +/** @typedef {import("./Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./Source").SourceAndMap} SourceAndMap */ +/** @typedef {import("./Source").SourceValue} SourceValue */ +/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */ +/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */ +/** @typedef {import("./helpers/streamChunks").OnName} OnName */ +/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */ +/** @typedef {import("./helpers/streamChunks").Options} Options */ +declare class OriginalSource extends Source { + /** + * @param {string | Buffer} value value + * @param {string} name name + */ + constructor(value: string | Buffer, name: string); + /** + * @type {undefined | string} + */ + _value: undefined | string; + /** + * @type {undefined | Buffer} + */ + _valueAsBuffer: undefined | Buffer; + /** + * @type {string} + */ + _name: string; + getName(): string; + _cachedSize: number | undefined; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} _onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + _onName: OnName, + ): GeneratedSourceInfo; +} +declare namespace OriginalSource { + export { + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + }; +} +import Source = require("./Source"); +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; diff --git a/types/PrefixSource.d.ts b/types/PrefixSource.d.ts new file mode 100644 index 0000000..92586c0 --- /dev/null +++ b/types/PrefixSource.d.ts @@ -0,0 +1,59 @@ +export = PrefixSource; +declare class PrefixSource extends Source { + /** + * @param {string} prefix prefix + * @param {string | Buffer | Source} source source + */ + constructor(prefix: string, source: string | Buffer | Source); + /** + * @type {string} + */ + _prefix: string; + /** + * @type {Source} + */ + _source: Source; + getPrefix(): string; + original(): Source; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + ): GeneratedSourceInfo; +} +declare namespace PrefixSource { + export { + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + }; +} +import Source = require("./Source"); +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; diff --git a/types/RawSource.d.ts b/types/RawSource.d.ts new file mode 100644 index 0000000..eb61ffb --- /dev/null +++ b/types/RawSource.d.ts @@ -0,0 +1,75 @@ +export = RawSource; +/** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */ +/** @typedef {import("./Source").HashLike} HashLike */ +/** @typedef {import("./Source").MapOptions} MapOptions */ +/** @typedef {import("./Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./Source").SourceValue} SourceValue */ +/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */ +/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */ +/** @typedef {import("./helpers/streamChunks").OnName} OnName */ +/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */ +/** @typedef {import("./helpers/streamChunks").Options} Options */ +declare class RawSource extends Source { + /** + * @param {string | Buffer} value value + * @param {boolean=} convertToString convert to string + */ + constructor(value: string | Buffer, convertToString?: boolean | undefined); + /** + * @type {boolean} + */ + _valueIsBuffer: boolean; + /** + * @type {undefined | string | Buffer} + */ + _value: undefined | string | Buffer; + /** + * @type {undefined | Buffer} + */ + _valueAsBuffer: undefined | Buffer; + /** + * @type {undefined | string} + */ + _valueAsString: undefined | string; + isBuffer(): boolean; + _cachedSize: number | undefined; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + ): GeneratedSourceInfo; +} +declare namespace RawSource { + export { + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + }; +} +import Source = require("./Source"); +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; diff --git a/types/ReplaceSource.d.ts b/types/ReplaceSource.d.ts new file mode 100644 index 0000000..8ffd63d --- /dev/null +++ b/types/ReplaceSource.d.ts @@ -0,0 +1,107 @@ +export = ReplaceSource; +declare class ReplaceSource extends Source { + /** + * @param {Source} source source + * @param {string=} name name + */ + constructor(source: Source, name?: string | undefined); + /** + * @type {Source} + */ + _source: Source; + /** + * @type {string | undefined} + */ + _name: string | undefined; + /** @type {Replacement[]} */ + _replacements: Replacement[]; + /** + * @type {boolean} + */ + _isSorted: boolean; + getName(): string | undefined; + getReplacements(): Replacement[]; + /** + * @param {number} start start + * @param {number} end end + * @param {string} newValue new value + * @param {string=} name name + * @returns {void} + */ + replace( + start: number, + end: number, + newValue: string, + name?: string | undefined, + ): void; + /** + * @param {number} pos pos + * @param {string} newValue new value + * @param {string=} name name + * @returns {void} + */ + insert(pos: number, newValue: string, name?: string | undefined): void; + original(): Source; + _sortReplacements(): void; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + ): GeneratedSourceInfo; +} +declare namespace ReplaceSource { + export { + Replacement, + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + }; +} +import Source = require("./Source"); +declare class Replacement { + /** + * @param {number} start start + * @param {number} end end + * @param {string} content content + * @param {string=} name name + */ + constructor( + start: number, + end: number, + content: string, + name?: string | undefined, + ); + start: number; + end: number; + content: string; + name: string | undefined; + index: number | undefined; +} +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; diff --git a/types/SizeOnlySource.d.ts b/types/SizeOnlySource.d.ts new file mode 100644 index 0000000..9835ce1 --- /dev/null +++ b/types/SizeOnlySource.d.ts @@ -0,0 +1,24 @@ +export = SizeOnlySource; +/** @typedef {import("./Source").HashLike} HashLike */ +/** @typedef {import("./Source").MapOptions} MapOptions */ +/** @typedef {import("./Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./Source").SourceValue} SourceValue */ +declare class SizeOnlySource extends Source { + /** + * @param {number} size size + */ + constructor(size: number); + /** + * @type {number} + */ + _size: number; + _error(): Error; +} +declare namespace SizeOnlySource { + export { HashLike, MapOptions, RawSourceMap, SourceValue }; +} +import Source = require("./Source"); +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceValue = import("./Source").SourceValue; diff --git a/types/Source.d.ts b/types/Source.d.ts new file mode 100644 index 0000000..4f5900d --- /dev/null +++ b/types/Source.d.ts @@ -0,0 +1,179 @@ +export = Source; +/** + * @typedef {object} MapOptions + * @property {boolean=} columns need columns? + * @property {boolean=} module is module + */ +/** + * @typedef {object} RawSourceMap + * @property {number} version version + * @property {string[]} sources sources + * @property {string[]} names names + * @property {string=} sourceRoot source root + * @property {string[]=} sourcesContent sources content + * @property {string} mappings mappings + * @property {string} file file + * @property {string=} debugId debug id + * @property {number[]=} ignoreList ignore list + */ +/** @typedef {string | Buffer} SourceValue */ +/** + * @typedef {object} SourceAndMap + * @property {SourceValue} source source + * @property {RawSourceMap | null} map map + */ +/** + * @typedef {object} HashLike + * @property {(data: string | Buffer, inputEncoding?: string) => HashLike} update make hash update + * @property {(encoding?: string) => string | Buffer} digest get hash digest + */ +/** + * @typedef {object} ClearCacheOptions + * @property {boolean=} maps drop cached source maps (default `true`) + * @property {boolean=} source drop cached source/buffer copies (default `true`) + * @property {boolean=} parsedMap drop the parsed object form of cached source maps on `SourceMapSource` instances (default `false` — re-parsing JSON is significantly more expensive than `toString`). Only takes effect when a serialized form (buffer or string) is also retained, so the data remains recoverable. + */ +declare class Source { + /** + * @returns {SourceValue} source + */ + source(): SourceValue; + /** + * @returns {Buffer} buffer + */ + buffer(): Buffer; + /** + * @returns {Buffer[]} buffers + */ + buffers(): Buffer[]; + /** + * @returns {number} size + */ + size(): number; + /** + * @param {MapOptions=} options map options + * @returns {RawSourceMap | null} map + */ + map(options?: MapOptions | undefined): RawSourceMap | null; + /** + * @param {MapOptions=} options map options + * @returns {SourceAndMap} source and map + */ + sourceAndMap(options?: MapOptions | undefined): SourceAndMap; + /** + * @param {HashLike} hash hash + * @returns {void} + */ + updateHash(hash: HashLike): void; + /** + * Release cached data held by this source. clearCache is a memory + * hint: it never affects correctness or output, only how expensive + * the next read is. Subclasses override; the base is a no-op so + * every Source supports the call. Composite sources always recurse + * into wrapped sources. When the same child is reachable via several + * parents (e.g. modules shared across webpack chunks), pass a shared + * `visited` WeakSet so each subtree is walked at most once. + * Not safe to call concurrently with source/map/sourceAndMap/ + * streamChunks/updateHash on the same instance. + * @param {ClearCacheOptions=} options selectors + * @param {WeakSet=} visited de-duplication set shared across calls + * @returns {void} + */ + clearCache( + options?: ClearCacheOptions | undefined, + visited?: WeakSet | undefined, + ): void; +} +declare namespace Source { + export { + MapOptions, + RawSourceMap, + SourceValue, + SourceAndMap, + HashLike, + ClearCacheOptions, + }; +} +type MapOptions = { + /** + * need columns? + */ + columns?: boolean | undefined; + /** + * is module + */ + module?: boolean | undefined; +}; +type RawSourceMap = { + /** + * version + */ + version: number; + /** + * sources + */ + sources: string[]; + /** + * names + */ + names: string[]; + /** + * source root + */ + sourceRoot?: string | undefined; + /** + * sources content + */ + sourcesContent?: string[] | undefined; + /** + * mappings + */ + mappings: string; + /** + * file + */ + file: string; + /** + * debug id + */ + debugId?: string | undefined; + /** + * ignore list + */ + ignoreList?: number[] | undefined; +}; +type SourceValue = string | Buffer; +type SourceAndMap = { + /** + * source + */ + source: SourceValue; + /** + * map + */ + map: RawSourceMap | null; +}; +type HashLike = { + /** + * make hash update + */ + update: (data: string | Buffer, inputEncoding?: string) => HashLike; + /** + * get hash digest + */ + digest: (encoding?: string) => string | Buffer; +}; +type ClearCacheOptions = { + /** + * drop cached source maps (default `true`) + */ + maps?: boolean | undefined; + /** + * drop cached source/buffer copies (default `true`) + */ + source?: boolean | undefined; + /** + * drop the parsed object form of cached source maps on `SourceMapSource` instances (default `false` — re-parsing JSON is significantly more expensive than `toString`). Only takes effect when a serialized form (buffer or string) is also retained, so the data remains recoverable. + */ + parsedMap?: boolean | undefined; +}; diff --git a/types/SourceMapSource.d.ts b/types/SourceMapSource.d.ts new file mode 100644 index 0000000..3945a04 --- /dev/null +++ b/types/SourceMapSource.d.ts @@ -0,0 +1,136 @@ +export = SourceMapSource; +/** @typedef {import("./Source").ClearCacheOptions} ClearCacheOptions */ +/** @typedef {import("./Source").HashLike} HashLike */ +/** @typedef {import("./Source").MapOptions} MapOptions */ +/** @typedef {import("./Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./Source").SourceAndMap} SourceAndMap */ +/** @typedef {import("./Source").SourceValue} SourceValue */ +/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */ +/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */ +/** @typedef {import("./helpers/streamChunks").OnName} OnName */ +/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */ +/** @typedef {import("./helpers/streamChunks").Options} Options */ +declare class SourceMapSource extends Source { + /** + * @param {string | Buffer} value value + * @param {string} name name + * @param {string | Buffer | RawSourceMap=} sourceMap source map + * @param {SourceValue=} originalSource original source + * @param {(null | string | Buffer | RawSourceMap)=} innerSourceMap inner source map + * @param {boolean=} removeOriginalSource do remove original source + */ + constructor( + value: string | Buffer, + name: string, + sourceMap?: (string | Buffer | RawSourceMap) | undefined, + originalSource?: SourceValue | undefined, + innerSourceMap?: (null | string | Buffer | RawSourceMap) | undefined, + removeOriginalSource?: boolean | undefined, + ); + /** + * @type {undefined | string} + */ + _valueAsString: undefined | string; + /** + * @type {undefined | Buffer} + */ + _valueAsBuffer: undefined | Buffer; + _name: string; + _hasSourceMap: boolean; + /** + * @type {undefined | RawSourceMap} + */ + _sourceMapAsObject: undefined | RawSourceMap; + /** + * @type {undefined | string} + */ + _sourceMapAsString: undefined | string; + /** + * @type {undefined | Buffer} + */ + _sourceMapAsBuffer: undefined | Buffer; + _hasOriginalSource: boolean; + _originalSourceAsString: string | undefined; + _originalSourceAsBuffer: Buffer | undefined; + _hasInnerSourceMap: boolean; + /** + * @type {undefined | RawSourceMap} + */ + _innerSourceMapAsObject: undefined | RawSourceMap; + /** + * @type {undefined | string} + */ + _innerSourceMapAsString: undefined | string; + /** + * @type {undefined | Buffer} + */ + _innerSourceMapAsBuffer: undefined | Buffer; + _removeOriginalSource: boolean | undefined; + /** + * @returns {[Buffer, string, Buffer, Buffer | undefined, Buffer | undefined, boolean | undefined]} args + */ + getArgsAsBuffers(): [ + Buffer, + string, + Buffer, + Buffer | undefined, + Buffer | undefined, + boolean | undefined, + ]; + _cachedSize: number | undefined; + /** + * @returns {undefined | Buffer} buffer + */ + _originalSourceBuffer(): undefined | Buffer; + _originalSourceString(): string | undefined; + _innerSourceMapObject(): any; + _innerSourceMapBuffer(): Buffer | undefined; + /** + * @returns {string} result + */ + _innerSourceMapString(): string; + _sourceMapObject(): any; + _sourceMapBuffer(): Buffer; + _sourceMapString(): string; + /** + * @param {Options} options options + * @param {OnChunk} onChunk called for each chunk of code + * @param {OnSource} onSource called for each source + * @param {OnName} onName called for each name + * @returns {GeneratedSourceInfo} generated source info + */ + streamChunks( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + ): GeneratedSourceInfo; +} +declare namespace SourceMapSource { + export { + ClearCacheOptions, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + }; +} +import Source = require("./Source"); +type ClearCacheOptions = import("./Source").ClearCacheOptions; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type Options = import("./helpers/streamChunks").Options; diff --git a/types/helpers/createMappingsSerializer.d.ts b/types/helpers/createMappingsSerializer.d.ts new file mode 100644 index 0000000..3325cc6 --- /dev/null +++ b/types/helpers/createMappingsSerializer.d.ts @@ -0,0 +1,60 @@ +export = createMappingsSerializer; +/** + * @param {{ columns?: boolean }=} options options + * @returns {MappingsSerializer} mappings serializer + */ +declare function createMappingsSerializer( + options?: + | { + columns?: boolean; + } + | undefined, +): MappingsSerializer; +declare namespace createMappingsSerializer { + export { createMappingsWriter, MappingsSerializer, MappingsWriter }; +} +/** + * @param {{ columns?: boolean }=} options options + * @returns {MappingsWriter} push-based mappings writer + */ +declare function createMappingsWriter( + options?: + | { + columns?: boolean; + } + | undefined, +): MappingsWriter; +type MappingsSerializer = ( + generatedLine: number, + generatedColumn: number, + sourceIndex: number, + originalLine: number, + originalColumn: number, + nameIndex: number, +) => string; +/** + * A push-based serializer: `add()` appends one mapping to an internal + * byte buffer, `finish()` materialises the whole `mappings` string in a + * single allocation. Compared to the string-returning + * {@link MappingsSerializer} this avoids every per-mapping intermediate + * string (each VLQ digit concatenation) plus the caller-side + * `mappings += str` cons chain — together the dominant allocation site + * of `map()` / `sourceAndMap()`. + */ +type MappingsWriter = { + /** + * append one mapping + */ + add: ( + generatedLine: number, + generatedColumn: number, + sourceIndex: number, + originalLine: number, + originalColumn: number, + nameIndex: number, + ) => void; + /** + * materialise the mappings string + */ + finish: () => string; +}; diff --git a/types/helpers/getFromStreamChunks.d.ts b/types/helpers/getFromStreamChunks.d.ts new file mode 100644 index 0000000..ade8ce6 --- /dev/null +++ b/types/helpers/getFromStreamChunks.d.ts @@ -0,0 +1,16 @@ +export function getMap( + source: SourceLikeWithStreamChunks, + options?: Options | undefined, +): RawSourceMap | null; +export function getSourceAndMap( + inputSource: SourceLikeWithStreamChunks, + options?: Options | undefined, +): SourceAndMap; +export type RawSourceMap = import("../Source").RawSourceMap; +export type SourceAndMap = import("../Source").SourceAndMap; +export type Options = import("./streamChunks").Options; +export type StreamChunksFunction = + import("./streamChunks").StreamChunksFunction; +export type SourceLikeWithStreamChunks = { + streamChunks: StreamChunksFunction; +}; diff --git a/types/helpers/getGeneratedSourceInfo.d.ts b/types/helpers/getGeneratedSourceInfo.d.ts new file mode 100644 index 0000000..c856c07 --- /dev/null +++ b/types/helpers/getGeneratedSourceInfo.d.ts @@ -0,0 +1,31 @@ +export = getGeneratedSourceInfo; +/** + * @typedef {object} GeneratedSourceInfo + * @property {number=} generatedLine generated line + * @property {number=} generatedColumn generated column + * @property {string=} source source + */ +/** + * @param {string | undefined} source source + * @returns {GeneratedSourceInfo} source info + */ +declare function getGeneratedSourceInfo( + source: string | undefined, +): GeneratedSourceInfo; +declare namespace getGeneratedSourceInfo { + export { GeneratedSourceInfo }; +} +type GeneratedSourceInfo = { + /** + * generated line + */ + generatedLine?: number | undefined; + /** + * generated column + */ + generatedColumn?: number | undefined; + /** + * source + */ + source?: string | undefined; +}; diff --git a/types/helpers/getName.d.ts b/types/helpers/getName.d.ts new file mode 100644 index 0000000..4594255 --- /dev/null +++ b/types/helpers/getName.d.ts @@ -0,0 +1,15 @@ +export = getName; +/** @typedef {import("../Source").RawSourceMap} RawSourceMap */ +/** + * @param {RawSourceMap} sourceMap source map + * @param {number} index index + * @returns {string | undefined | null} name + */ +declare function getName( + sourceMap: RawSourceMap, + index: number, +): string | undefined | null; +declare namespace getName { + export { RawSourceMap }; +} +type RawSourceMap = import("../Source").RawSourceMap; diff --git a/types/helpers/getSource.d.ts b/types/helpers/getSource.d.ts new file mode 100644 index 0000000..4d4c98a --- /dev/null +++ b/types/helpers/getSource.d.ts @@ -0,0 +1,15 @@ +export = getSource; +/** @typedef {import("../Source").RawSourceMap} RawSourceMap */ +/** + * @param {RawSourceMap} sourceMap source map + * @param {number} index index + * @returns {string | null} name + */ +declare function getSource( + sourceMap: RawSourceMap, + index: number, +): string | null; +declare namespace getSource { + export { RawSourceMap }; +} +type RawSourceMap = import("../Source").RawSourceMap; diff --git a/types/helpers/readMappings.d.ts b/types/helpers/readMappings.d.ts new file mode 100644 index 0000000..52b75eb --- /dev/null +++ b/types/helpers/readMappings.d.ts @@ -0,0 +1,19 @@ +export = readMappings; +/** @typedef {(generatedLine: number, generatedColumn: number, sourceIndex: number, originalLine: number, originalColumn: number, nameIndex: number) => void} OnMapping */ +/** + * @param {string} mappings the mappings string + * @param {OnMapping} onMapping called for each mapping + * @returns {void} + */ +declare function readMappings(mappings: string, onMapping: OnMapping): void; +declare namespace readMappings { + export { OnMapping }; +} +type OnMapping = ( + generatedLine: number, + generatedColumn: number, + sourceIndex: number, + originalLine: number, + originalColumn: number, + nameIndex: number, +) => void; diff --git a/types/helpers/splitIntoLines.d.ts b/types/helpers/splitIntoLines.d.ts new file mode 100644 index 0000000..38f4c40 --- /dev/null +++ b/types/helpers/splitIntoLines.d.ts @@ -0,0 +1,6 @@ +export = splitIntoLines; +/** + * @param {string} str string + * @returns {string[]} array of string separated by lines + */ +declare function splitIntoLines(str: string): string[]; diff --git a/types/helpers/splitIntoPotentialTokens.d.ts b/types/helpers/splitIntoPotentialTokens.d.ts new file mode 100644 index 0000000..3341903 --- /dev/null +++ b/types/helpers/splitIntoPotentialTokens.d.ts @@ -0,0 +1,37 @@ +export = splitIntoPotentialTokens; +/** + * Array-returning variant. Kept as a standalone loop rather than wrapping + * `eachPotentialToken` with a per-token callback: the callback indirection + * measurably slows this hot scan (V8 can no longer inline the slice/push), + * and the two only share the same small, well-tested classification table. + * @param {string} str string + * @returns {string[] | null} array of string separated by potential tokens + */ +declare function splitIntoPotentialTokens(str: string): string[] | null; +declare namespace splitIntoPotentialTokens { + export { eachPotentialToken, OnPotentialToken }; +} +/** + * @callback OnPotentialToken + * @param {number} start start offset (inclusive) + * @param {number} end end offset (exclusive) + * @param {boolean} newline whether the token ends with a `\n` + * @returns {void} + */ +/** + * Streaming core: report each potential token by its `[start, end)` bounds + * instead of materialising substrings. The single real consumer + * (`OriginalSource.streamChunks`) slices on demand — and skips slicing + * entirely when emitting the final source (the `map()` / `sourceAndMap()` + * paths, which discard the chunk text) — so this avoids both the + * intermediate results array and every per-token `String.slice` allocation + * in the dominant case. + * @param {string} str string + * @param {OnPotentialToken} onToken called for each token + * @returns {void} + */ +declare function eachPotentialToken( + str: string, + onToken: OnPotentialToken, +): void; +type OnPotentialToken = (start: number, end: number, newline: boolean) => void; diff --git a/types/helpers/streamAndGetSourceAndMap.d.ts b/types/helpers/streamAndGetSourceAndMap.d.ts new file mode 100644 index 0000000..6529e10 --- /dev/null +++ b/types/helpers/streamAndGetSourceAndMap.d.ts @@ -0,0 +1,46 @@ +export = streamAndGetSourceAndMap; +/** @typedef {import("../Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./streamChunks").GeneratedSourceInfo} GeneratedSourceInfo */ +/** @typedef {import("./streamChunks").OnChunk} OnChunk */ +/** @typedef {import("./streamChunks").OnName} OnName */ +/** @typedef {import("./streamChunks").OnSource} OnSource */ +/** @typedef {import("./streamChunks").Options} Options */ +/** @typedef {import("./streamChunks").SourceMaybeWithStreamChunksFunction} SourceMaybeWithStreamChunksFunction */ +/** + * @param {SourceMaybeWithStreamChunksFunction} inputSource input source + * @param {Options} options options + * @param {OnChunk} onChunk on chunk + * @param {OnSource} onSource on source + * @param {OnName} onName on name + * @returns {{ result: GeneratedSourceInfo, source: string, map: RawSourceMap | null }} result + */ +declare function streamAndGetSourceAndMap( + inputSource: SourceMaybeWithStreamChunksFunction, + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, +): { + result: GeneratedSourceInfo; + source: string; + map: RawSourceMap | null; +}; +declare namespace streamAndGetSourceAndMap { + export { + RawSourceMap, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + Options, + SourceMaybeWithStreamChunksFunction, + }; +} +type RawSourceMap = import("../Source").RawSourceMap; +type GeneratedSourceInfo = import("./streamChunks").GeneratedSourceInfo; +type OnChunk = import("./streamChunks").OnChunk; +type OnName = import("./streamChunks").OnName; +type OnSource = import("./streamChunks").OnSource; +type Options = import("./streamChunks").Options; +type SourceMaybeWithStreamChunksFunction = + import("./streamChunks").SourceMaybeWithStreamChunksFunction; diff --git a/types/helpers/streamChunks.d.ts b/types/helpers/streamChunks.d.ts new file mode 100644 index 0000000..f1b251f --- /dev/null +++ b/types/helpers/streamChunks.d.ts @@ -0,0 +1,52 @@ +declare namespace _exports { + export { + Source, + GeneratedSourceInfo, + OnChunk, + OnSource, + OnName, + Options, + StreamChunksFunction, + SourceMaybeWithStreamChunksFunction, + }; +} +declare function _exports( + source: SourceMaybeWithStreamChunksFunction, + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, +): GeneratedSourceInfo; +export = _exports; +type Source = import("../Source"); +type GeneratedSourceInfo = + import("./getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = ( + chunk: string | undefined, + generatedLine: number, + generatedColumn: number, + sourceIndex: number, + originalLine: number, + originalColumn: number, + nameIndex: number, +) => void; +type OnSource = ( + sourceIndex: number, + source: string | null, + sourceContent: string | undefined, +) => void; +type OnName = (nameIndex: number, name: string) => void; +type Options = { + source?: boolean; + finalSource?: boolean; + columns?: boolean; +}; +type StreamChunksFunction = ( + options: Options, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, +) => any; +type SourceMaybeWithStreamChunksFunction = Source & { + streamChunks?: StreamChunksFunction; +}; diff --git a/types/helpers/streamChunksOfCombinedSourceMap.d.ts b/types/helpers/streamChunksOfCombinedSourceMap.d.ts new file mode 100644 index 0000000..30d65b3 --- /dev/null +++ b/types/helpers/streamChunksOfCombinedSourceMap.d.ts @@ -0,0 +1,42 @@ +export = streamChunksOfCombinedSourceMap; +/** @typedef {import("../Source").RawSourceMap} RawSourceMap */ +/** @typedef {import("./getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */ +/** @typedef {import("./streamChunks").OnChunk} onChunk */ +/** @typedef {import("./streamChunks").OnName} OnName */ +/** @typedef {import("./streamChunks").OnSource} OnSource */ +/** + * @param {string} source source + * @param {RawSourceMap} sourceMap source map + * @param {string} innerSourceName inner source name + * @param {string} innerSource inner source + * @param {RawSourceMap} innerSourceMap inner source map + * @param {boolean | undefined} removeInnerSource do remove inner source + * @param {onChunk} onChunk on chunk + * @param {OnSource} onSource on source + * @param {OnName} onName on name + * @param {boolean} finalSource finalSource + * @param {boolean} columns columns + * @returns {GeneratedSourceInfo} generated source info + */ +declare function streamChunksOfCombinedSourceMap( + source: string, + sourceMap: RawSourceMap, + innerSourceName: string, + innerSource: string, + innerSourceMap: RawSourceMap, + removeInnerSource: boolean | undefined, + onChunk: onChunk, + onSource: OnSource, + onName: OnName, + finalSource: boolean, + columns: boolean, +): GeneratedSourceInfo; +declare namespace streamChunksOfCombinedSourceMap { + export { RawSourceMap, GeneratedSourceInfo, onChunk, OnName, OnSource }; +} +type RawSourceMap = import("../Source").RawSourceMap; +type GeneratedSourceInfo = + import("./getGeneratedSourceInfo").GeneratedSourceInfo; +type onChunk = import("./streamChunks").OnChunk; +type OnName = import("./streamChunks").OnName; +type OnSource = import("./streamChunks").OnSource; diff --git a/types/helpers/streamChunksOfRawSource.d.ts b/types/helpers/streamChunksOfRawSource.d.ts new file mode 100644 index 0000000..65b6327 --- /dev/null +++ b/types/helpers/streamChunksOfRawSource.d.ts @@ -0,0 +1,16 @@ +declare namespace _exports { + export { GeneratedSourceInfo, OnChunk, OnName, OnSource }; +} +declare function _exports( + source: string, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + finalSource: boolean, +): GeneratedSourceInfo; +export = _exports; +type GeneratedSourceInfo = + import("./getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./streamChunks").OnChunk; +type OnName = import("./streamChunks").OnName; +type OnSource = import("./streamChunks").OnSource; diff --git a/types/helpers/streamChunksOfSourceMap.d.ts b/types/helpers/streamChunksOfSourceMap.d.ts new file mode 100644 index 0000000..ae919b0 --- /dev/null +++ b/types/helpers/streamChunksOfSourceMap.d.ts @@ -0,0 +1,19 @@ +declare namespace _exports { + export { RawSourceMap, GeneratedSourceInfo, OnChunk, OnName, OnSource }; +} +declare function _exports( + source: string, + sourceMap: RawSourceMap, + onChunk: OnChunk, + onSource: OnSource, + onName: OnName, + finalSource: boolean, + columns: boolean, +): GeneratedSourceInfo; +export = _exports; +type RawSourceMap = import("../Source").RawSourceMap; +type GeneratedSourceInfo = + import("./getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./streamChunks").OnChunk; +type OnName = import("./streamChunks").OnName; +type OnSource = import("./streamChunks").OnSource; diff --git a/types/helpers/stringBufferUtils.d.ts b/types/helpers/stringBufferUtils.d.ts new file mode 100644 index 0000000..3d90ec1 --- /dev/null +++ b/types/helpers/stringBufferUtils.d.ts @@ -0,0 +1,55 @@ +/** + * Disables the optimization to save both string and buffer in memory. This + * may increase performance but should reduce memory usage in the Webpack + * compiler. + * @returns {void} + */ +export function disableDualStringBufferCaching(): void; +/** + * Enables an optimization to save both string and buffer in memory to avoid + * repeat conversions between the two formats when they are requested. This + * is enabled by default. This option can improve performance but can consume + * additional memory since values are stored twice. + * @returns {void} + */ +export function enableDualStringBufferCaching(): void; +/** + * Starts a memory optimization to avoid repeat copies of the same string in + * memory by caching a single reference to the string. This can reduce memory + * usage if the same string is repeated many times in the compiler, such as + * when Webpack layers are used with the same files. + * + * {@link exitStringInterningRange} should be called when string interning is + * no longer necessary to free up the memory used by the interned strings. If + * {@link enterStringInterningRange} has been called multiple times, then + * this method may not immediately free all the memory until + * {@link exitStringInterningRange} has been called to end all string + * interning ranges. + * @returns {void} + */ +export function enterStringInterningRange(): void; +/** + * Stops the current string interning range. Once all string interning ranges + * have been exited, this method will free all the memory used by the interned + * strings. This method should be called once for each time that + * {@link enterStringInterningRange} was called. + * @returns {void} + */ +export function exitStringInterningRange(): void; +/** + * Saves the string in a map to ensure that only one copy of the string exists + * in memory at a given time. This is controlled by {@link enableStringInterning} + * and {@link disableStringInterning}. Callers are expect to manage the memory + * of the interned strings by calling {@link disableStringInterning} after the + * compiler no longer needs to save the interned memory. + * @param {string} str A string to be interned. + * @returns {string} The original string or a reference to an existing string of the same value if it has already been interned. + */ +export function internString(str: string): string; +/** + * @returns {boolean} Whether the optimization to cache copies of both the + * string and buffer version of source content is enabled. This is enabled by + * default to improve performance but can consume more memory since values are + * stored twice. + */ +export function isDualStringBufferCachingEnabled(): boolean; diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..3d98f31 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,49 @@ +declare namespace _exports { + export { + CachedData, + SourceLike, + ConcatSourceChild, + Replacement, + HashLike, + MapOptions, + RawSourceMap, + SourceAndMap, + SourceValue, + GeneratedSourceInfo, + OnChunk, + OnName, + OnSource, + StreamChunksOptions, + }; +} +declare namespace _exports { + const Source: typeof import("./Source"); + const RawSource: typeof import("./RawSource"); + const OriginalSource: typeof import("./OriginalSource"); + const SourceMapSource: typeof import("./SourceMapSource"); + const CachedSource: typeof import("./CachedSource"); + const ConcatSource: typeof import("./ConcatSource"); + const ReplaceSource: typeof import("./ReplaceSource"); + const PrefixSource: typeof import("./PrefixSource"); + const SizeOnlySource: typeof import("./SizeOnlySource"); + const CompatSource: typeof import("./CompatSource"); + namespace util { + const stringBufferUtils: typeof import("./helpers/stringBufferUtils"); + } +} +export = _exports; +type CachedData = import("./CachedSource").CachedData; +type SourceLike = import("./CompatSource").SourceLike; +type ConcatSourceChild = import("./ConcatSource").Child; +type Replacement = import("./ReplaceSource").Replacement; +type HashLike = import("./Source").HashLike; +type MapOptions = import("./Source").MapOptions; +type RawSourceMap = import("./Source").RawSourceMap; +type SourceAndMap = import("./Source").SourceAndMap; +type SourceValue = import("./Source").SourceValue; +type GeneratedSourceInfo = + import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo; +type OnChunk = import("./helpers/streamChunks").OnChunk; +type OnName = import("./helpers/streamChunks").OnName; +type OnSource = import("./helpers/streamChunks").OnSource; +type StreamChunksOptions = import("./helpers/streamChunks").Options;