From 3dc357bee075e92904ea097ef80a51ff9aa172d7 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Sun, 4 Sep 2022 05:17:24 -0300 Subject: [PATCH] feat: expose parser and YTNodes as public APIs --- browser.ts | 7 +++++-- examples/parser/index.ts | 4 ++-- index.ts | 7 +++++-- package.json | 15 ++++++--------- scripts/build-parser-map.js | 5 ++++- src/parser/map.ts | 2 ++ 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/browser.ts b/browser.ts index 05f534d6..bd0082cd 100644 --- a/browser.ts +++ b/browser.ts @@ -1,6 +1,9 @@ // Deno and browser runtimes import Innertube from './src/Innertube'; -export { default as Innertube } from './src/Innertube.js'; + export * from './src/utils'; -export default Innertube; +export { YTNodes } from './src/parser/map'; +export { default as Parser } from './src/parser'; +export { default as Innertube } from './src/Innertube'; +export default Innertube; \ No newline at end of file diff --git a/examples/parser/index.ts b/examples/parser/index.ts index a9f52fae..425115b5 100644 --- a/examples/parser/index.ts +++ b/examples/parser/index.ts @@ -1,4 +1,4 @@ -import Parser from 'youtubei.js/dist/src/parser'; +import { Parser } from 'youtubei.js'; import SectionList from 'youtubei.js/dist/src/parser/classes/SectionList'; import SingleColumnBrowseResults from 'youtubei.js/dist/src/parser/classes/SingleColumnBrowseResults'; @@ -32,6 +32,6 @@ if (!tab) if (!tab.content) throw new Error('Target tab appears to be empty'); -const sections = tab.content?.as(SectionList).contents.array().as(MusicCarouselShelf, MusicShelf); +const sections = tab.content?.as(SectionList).contents.array().as(MusicCarouselShelf, MusicDescriptionShelf, MusicShelf); console.info('Sections:', sections); \ No newline at end of file diff --git a/index.ts b/index.ts index f24a7a0d..4c8dc91f 100644 --- a/index.ts +++ b/index.ts @@ -13,6 +13,9 @@ if (getRuntime() === 'node') { } import Innertube from './src/Innertube'; -export { default as Innertube } from './src/Innertube.js'; + export * from './src/utils'; -export default Innertube; +export { YTNodes } from './src/parser/map'; +export { default as Parser } from './src/parser'; +export { default as Innertube } from './src/Innertube'; +export default Innertube; \ No newline at end of file diff --git a/package.json b/package.json index b2182efb..a99f306b 100644 --- a/package.json +++ b/package.json @@ -16,20 +16,19 @@ ], "directories": { "test": "./test", - "typings": "./dist", "examples": "./examples", - "src": "./dist/src" + "dist": "./dist" }, "scripts": { "test": "npx jest --verbose", "lint": "npx eslint ./src", "lint:fix": "npx eslint --fix ./src", "build": "npm run build:parser-map && npm run build:proto && npm run bundle:browser && npm run bundle:browser:prod && npm run build:node", - "build:proto": "npx protoc --ts_out ./src/proto --proto_path ./src/proto ./src/proto/youtube.proto", "build:node": "npx tsc", - "build:parser-map": "node ./scripts/build-parser-map.js", "bundle:browser": "npx tsc --module esnext && npx esbuild ./dist/browser.js --banner:js=\"/* eslint-disable */\" --bundle --target=chrome58 --keep-names --format=esm --sourcemap --define:global=globalThis --outfile=./bundle/browser.js --platform=browser", "bundle:browser:prod": "npm run bundle:browser -- --outfile=./bundle/browser.min.js --minify", + "build:parser-map": "node ./scripts/build-parser-map.js", + "build:proto": "npx protoc --ts_out ./src/proto --proto_path ./src/proto ./src/proto/youtube.proto", "prepare": "npm run build", "watch": "npx tsc --watch" }, @@ -45,13 +44,11 @@ "undici": "^5.7.0" }, "devDependencies": { - "@protobuf-ts/plugin": "^2.7.0", - "@types/flat": "^5.0.2", - "@types/jest": "^28.1.7", - "@types/node": "^17.0.45", - "@types/user-agents": "^1.0.2", "@typescript-eslint/eslint-plugin": "^5.30.6", "@typescript-eslint/parser": "^5.30.6", + "@protobuf-ts/plugin": "^2.7.0", + "@types/jest": "^28.1.7", + "@types/node": "^17.0.45", "esbuild": "^0.14.49", "eslint": "^8.19.0", "eslint-plugin-tsdoc": "^0.2.16", diff --git a/scripts/build-parser-map.js b/scripts/build-parser-map.js index fc665472..5c12406c 100644 --- a/scripts/build-parser-map.js +++ b/scripts/build-parser-map.js @@ -3,6 +3,7 @@ const fs = require('fs'); const path = require('path'); const import_list = []; + const json = []; glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname }) @@ -18,7 +19,7 @@ glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname }) fs.writeFileSync( path.resolve(__dirname, '../src/parser/map.ts'), `// This file was auto generated, do not edit. -// See ./scripts/build-parser-json.js +// See ./scripts/build-parser-map.js import { YTNodeConstructor } from './helpers'; ${import_list.join('\n')} @@ -27,6 +28,8 @@ const map: Record = { ${json.join(',\n ')} }; +export const YTNodes = map; + /** * @param name - Name of the node to be parsed */ diff --git a/src/parser/map.ts b/src/parser/map.ts index d39ee9eb..15155ef3 100644 --- a/src/parser/map.ts +++ b/src/parser/map.ts @@ -524,6 +524,8 @@ const map: Record = { WatchNextTabbedResults }; +export const YTNodes = map; + /** * @param name - Name of the node to be parsed */