diff --git a/.changeset/smart-eyes-report.md b/.changeset/smart-eyes-report.md new file mode 100644 index 0000000..007029a --- /dev/null +++ b/.changeset/smart-eyes-report.md @@ -0,0 +1,9 @@ +--- +"google-sr-selectors": minor +"google-that": minor +"google-sr": minor +--- + +Migrate packages to ESM-first with CJS compatibility via dual build + +All packages have been migrated from CJS-first to ESM-first architecture. Existing users can continue using the packages without any code changes as both ESM and CJS builds are provided. \ No newline at end of file diff --git a/package.json b/package.json index b7025f5..e61e78c 100644 --- a/package.json +++ b/package.json @@ -1,44 +1,47 @@ { - "name": "gsr", - "private": true, - "repository": "https://github.com/typicalninja/google-sr", - "scripts": { - "build": "turbo run build --no-daemon", - "dev": "turbo run dev --parallel --no-daemon", - "test": "turbo run test --no-daemon --filter=google-sr -- --watch=false", - "build:packages": "turbo run build --no-daemon", - "build:docs": "typedoc ", - "lint": "biome lint --write", - "format": "biome format --write", - "check": "biome check --write", - "ci:publish": "pnpm publish -r --no-git-checks", - "ci:version": "changeset version", - "prepare": "is-ci || lefthook install" - }, - "author": "typicalninja", - "license": "Apache-2.0", - "engines": { - "node": ">=20.0.0", - "pnpm": ">=10.13.1" - }, + "name": "gsr", + "private": true, + "author": "typicalninja", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "git+https://github.com/typicalninja/google-sr.git" + }, + "scripts": { + "build": "turbo run build --no-daemon", + "dev": "turbo run dev --parallel --no-daemon", + "test": "turbo run test --no-daemon --filter=google-sr -- --watch=false", + "build:packages": "turbo run build --no-daemon", + "build:docs": "typedoc ", + "lint": "biome lint --write", + "format": "biome format --write", + "check": "biome check --write", + "ci:publish": "pnpm publish -r --no-git-checks", + "ci:version": "changeset version", + "prepare": "is-ci || lefthook install" + }, + "devDependencies": { + "@biomejs/biome": "2.0.6", + "@changesets/changelog-github": "^0.5.1", + "@changesets/cli": "^2.29.5", + "@commitlint/cli": "19.8.1", + "@commitlint/config-conventional": "19.8.1", + "is-ci": "4.1.0", + "lefthook": "^1.11.16", + "pkg-pr-new": "^0.0.54", + "tsup": "^8.5.0", + "turbo": "^2.5.4", + "typedoc": "^0.28.7", + "typescript": "^5.8.3" + }, "packageManager": "pnpm@10.13.1", - "devDependencies": { - "@biomejs/biome": "2.0.6", - "@changesets/changelog-github": "^0.5.1", - "@changesets/cli": "^2.29.5", - "@commitlint/cli": "19.8.1", - "@commitlint/config-conventional": "19.8.1", - "is-ci": "4.1.0", - "lefthook": "^1.11.16", - "pkg-pr-new": "^0.0.54", - "tsup": "^8.5.0", - "turbo": "^2.5.4", - "typedoc": "^0.28.7", - "typescript": "^5.8.3" - }, - "commitlint": { - "extends": [ - "@commitlint/config-conventional" - ] - } + "engines": { + "node": ">=20.0.0", + "pnpm": ">=10.13.1" + }, + "commitlint": { + "extends": [ + "@commitlint/config-conventional" + ] + } } diff --git a/packages/google-sr-selectors/.npmignore b/packages/google-sr-selectors/.npmignore deleted file mode 100644 index 2d350c0..0000000 --- a/packages/google-sr-selectors/.npmignore +++ /dev/null @@ -1,14 +0,0 @@ - -# Stop npm from publishing ts files -src -# Typescript -tsup.config.ts -tsconfig.json - -# tools -.turbo - -# Ignore api docs -API.md -# Ignore changelog -CHANGELOG.md \ No newline at end of file diff --git a/packages/google-sr-selectors/package.json b/packages/google-sr-selectors/package.json index b22e0c4..d9b54d4 100644 --- a/packages/google-sr-selectors/package.json +++ b/packages/google-sr-selectors/package.json @@ -1,34 +1,43 @@ { - "name": "google-sr-selectors", - "version": "2.0.0", - "description": "Html selectors for google search result pages.", - "repository": "https://github.com/typicalninja/google-sr", - "homepage": "https://typicalninja.github.io/google-sr/", - "exports": { - "types": "./dist/index.d.ts", - "require": "./dist/index.js", - "import": "./dist/index.mjs" - }, - "scripts": { - "build": "tsup", - "dev": "tsup --watch" - }, - "keywords": [ - "google-sr", - "gsr", - "google", - "googlesr", - "search", - "google-search", - "googlesearch", - "scraping", - "selectors", - "cheerio" - ], - "author": "typicalninja", - "license": "Apache-2.0", + "name": "google-sr-selectors", + "version": "2.0.0", + "description": "Html selectors for google search result pages.", + "repository": { + "type": "git", + "url": "git+https://github.com/typicalninja/google-sr.git" + }, + "homepage": "https://typicalninja.github.io/google-sr/", + "author": "typicalninja", + "license": "Apache-2.0", + "type": "module", + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "scripts": { + "build": "tsup", + "dev": "tsup --watch" + }, "engines": { - "node": ">=20.0.0", - "pnpm": ">=10.13.1" - } + "node": ">=20.0.0", + "pnpm": ">=10.13.1" + }, + "files": [ + "dist/", + "README.md" + ], + "keywords": [ + "google-sr", + "gsr", + "google", + "googlesr", + "search", + "google-search", + "googlesearch", + "scraping", + "selectors", + "cheerio" + ] } diff --git a/packages/google-sr-selectors/tsup.config.ts b/packages/google-sr-selectors/tsup.config.ts index 340312a..f3b6e6c 100644 --- a/packages/google-sr-selectors/tsup.config.ts +++ b/packages/google-sr-selectors/tsup.config.ts @@ -1,3 +1,3 @@ -import { createTsupConfig } from "../../tsup.config"; +import { createTsupConfig } from "../../tsup.config.js"; export default [createTsupConfig()]; diff --git a/packages/google-sr/.npmignore b/packages/google-sr/.npmignore deleted file mode 100644 index 9102fa1..0000000 --- a/packages/google-sr/.npmignore +++ /dev/null @@ -1,19 +0,0 @@ - -# Stop npm from publishing ts files -src - -# Stop npm from publishing test files -tests - -# Typescript -tsup.config.ts -tsconfig.json - -# tools -.turbo - - -# Ignore api docs -API.md -# Ignore changelog -CHANGELOG.md \ No newline at end of file diff --git a/packages/google-sr/package.json b/packages/google-sr/package.json index 6c0bf73..84e36d8 100644 --- a/packages/google-sr/package.json +++ b/packages/google-sr/package.json @@ -1,43 +1,51 @@ { - "name": "google-sr", - "version": "5.0.0", - "description": "Fast and efficient Package for scraping Google search results without the need for an API key", - "repository": "https://github.com/typicalninja/google-sr", - "homepage": "https://typicalninja.github.io/google-sr/", - "exports": { - "types": "./dist/index.d.mts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "scripts": { - "test": "vitest", - "build": "tsup", - "dev": "tsup --watch" - }, - "keywords": [ - "google-sr", - "gsr", - "google", - "googlesr", - "search", - "google-search", - "googlesearch", - "scraping" - ], - "author": "typicalninja", - "license": "Apache-2.0", - "dependencies": { - "cheerio": "1.1.0", - "google-sr-selectors": "workspace:^" - }, - "devDependencies": { - "@vitest/coverage-v8": "^3.2.4", - "@vitest/ui": "3.2.4", - "is-ci": "4.1.0", - "vitest": "^3.2.4" - }, + "name": "google-sr", + "version": "5.0.0", + "description": "Fast and efficient Package for scraping Google search results without the need for an API key", + "repository": { + "type": "git", + "url": "git+https://github.com/typicalninja/google-sr.git" + }, + "homepage": "https://typicalninja.github.io/google-sr/", + "type": "module", + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "scripts": { + "test": "vitest", + "build": "tsup", + "dev": "tsup --watch" + }, + "author": "typicalninja", + "license": "Apache-2.0", + "dependencies": { + "cheerio": "1.1.0", + "google-sr-selectors": "workspace:^" + }, + "devDependencies": { + "@vitest/coverage-v8": "^3.2.4", + "@vitest/ui": "3.2.4", + "vitest": "^3.2.4" + }, "engines": { - "node": ">=20.0.0", - "pnpm": ">=10.13.1" - } + "node": ">=20.0.0", + "pnpm": ">=10.13.1" + }, + "files": [ + "dist/", + "README.md" + ], + "keywords": [ + "google-sr", + "gsr", + "google", + "googlesr", + "search", + "google-search", + "googlesearch", + "scraping" + ] } diff --git a/packages/google-sr/src/constants.ts b/packages/google-sr/src/constants.ts index 14eb6e2..a3f5e51 100644 --- a/packages/google-sr/src/constants.ts +++ b/packages/google-sr/src/constants.ts @@ -7,7 +7,7 @@ import type { TimeResultNode, TranslateResultNode, UnitConversionResultNode, -} from "./results"; +} from "./results/index.js"; export const ResultTypes = { OrganicResult: "ORGANIC", diff --git a/packages/google-sr/src/index.ts b/packages/google-sr/src/index.ts index 41213cd..55f2618 100644 --- a/packages/google-sr/src/index.ts +++ b/packages/google-sr/src/index.ts @@ -1,5 +1,5 @@ -export * from "./constants"; -export * from "./results"; -export * from "./search"; +export * from "./constants.js"; +export * from "./results/index.js"; +export * from "./search.js"; -export type { SearchResultTypeFromParser } from "./utils"; +export type { SearchResultTypeFromParser } from "./utils.js"; diff --git a/packages/google-sr/src/results/conversion.ts b/packages/google-sr/src/results/conversion.ts index 65edb56..caaed8f 100644 --- a/packages/google-sr/src/results/conversion.ts +++ b/packages/google-sr/src/results/conversion.ts @@ -3,8 +3,8 @@ import { type ResultParser, ResultTypes, type SearchResultNodeLike, -} from "../constants"; -import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils"; +} from "../constants.js"; +import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils.js"; export interface UnitConversionResultNode extends SearchResultNodeLike { type: typeof ResultTypes.UnitConversionResult; diff --git a/packages/google-sr/src/results/dictionary.ts b/packages/google-sr/src/results/dictionary.ts index 1fd9a71..8e066b2 100644 --- a/packages/google-sr/src/results/dictionary.ts +++ b/packages/google-sr/src/results/dictionary.ts @@ -4,8 +4,8 @@ import { type ResultParser, ResultTypes, type SearchResultNodeLike, -} from "../constants"; -import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils"; +} from "../constants.js"; +import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils.js"; export interface DictionaryDefinition { definition: string; // The definition text diff --git a/packages/google-sr/src/results/index.ts b/packages/google-sr/src/results/index.ts index 684123f..1dd418d 100644 --- a/packages/google-sr/src/results/index.ts +++ b/packages/google-sr/src/results/index.ts @@ -1,7 +1,7 @@ -export * from "./conversion"; -export * from "./dictionary"; -export * from "./knowledge-panel"; -export * from "./news"; -export * from "./organic"; -export * from "./time"; -export * from "./translate"; +export * from "./conversion.js"; +export * from "./dictionary.js"; +export * from "./knowledge-panel.js"; +export * from "./news.js"; +export * from "./organic.js"; +export * from "./time.js"; +export * from "./translate.js"; diff --git a/packages/google-sr/src/results/knowledge-panel.ts b/packages/google-sr/src/results/knowledge-panel.ts index 5d3c93e..88602cb 100644 --- a/packages/google-sr/src/results/knowledge-panel.ts +++ b/packages/google-sr/src/results/knowledge-panel.ts @@ -3,12 +3,12 @@ import { type ResultParser, ResultTypes, type SearchResultNodeLike, -} from "../constants"; +} from "../constants.js"; import { coerceToStringOrUndefined, extractUrlFromGoogleLink, throwNoCheerioError, -} from "../utils"; +} from "../utils.js"; export interface KnowledgePanelMetadata { label: string; diff --git a/packages/google-sr/src/results/news.ts b/packages/google-sr/src/results/news.ts index b4f103c..b182ffa 100644 --- a/packages/google-sr/src/results/news.ts +++ b/packages/google-sr/src/results/news.ts @@ -3,12 +3,12 @@ import { type ResultParser, ResultTypes, type SearchResultNodeLike, -} from "../constants"; +} from "../constants.js"; import { coerceToStringOrUndefined, extractUrlFromGoogleLink, throwNoCheerioError, -} from "../utils"; +} from "../utils.js"; export interface NewsResultNode extends SearchResultNodeLike { type: typeof ResultTypes.NewsResult; diff --git a/packages/google-sr/src/results/organic.ts b/packages/google-sr/src/results/organic.ts index 6147ddf..e6de132 100644 --- a/packages/google-sr/src/results/organic.ts +++ b/packages/google-sr/src/results/organic.ts @@ -3,13 +3,13 @@ import { type ResultParser, ResultTypes, type SearchResultNodeLike, -} from "../constants"; +} from "../constants.js"; import { coerceToStringOrUndefined, extractUrlFromGoogleLink, type PartialExceptType, throwNoCheerioError, -} from "../utils"; +} from "../utils.js"; export interface OrganicResultNode extends SearchResultNodeLike { type: typeof ResultTypes.OrganicResult; diff --git a/packages/google-sr/src/results/time.ts b/packages/google-sr/src/results/time.ts index 7f1d7af..4df4f6c 100644 --- a/packages/google-sr/src/results/time.ts +++ b/packages/google-sr/src/results/time.ts @@ -4,8 +4,8 @@ import { type ResultParser, ResultTypes, type SearchResultNodeLike, -} from "../constants"; -import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils"; +} from "../constants.js"; +import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils.js"; export interface TimeResultNode extends SearchResultNodeLike { type: typeof ResultTypes.TimeResult; diff --git a/packages/google-sr/src/results/translate.ts b/packages/google-sr/src/results/translate.ts index 76b9465..692e864 100644 --- a/packages/google-sr/src/results/translate.ts +++ b/packages/google-sr/src/results/translate.ts @@ -4,8 +4,8 @@ import { ResultTypes, type SearchResultNodeLike, TranslateSourceTextRegex, -} from "../constants"; -import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils"; +} from "../constants.js"; +import { coerceToStringOrUndefined, throwNoCheerioError } from "../utils.js"; export interface TranslateResultNode extends SearchResultNodeLike { type: typeof ResultTypes.TranslateResult; diff --git a/packages/google-sr/src/search.ts b/packages/google-sr/src/search.ts index 99f7e8b..f8a9393 100644 --- a/packages/google-sr/src/search.ts +++ b/packages/google-sr/src/search.ts @@ -3,14 +3,14 @@ import type { ResultParser, SearchOptions, SearchOptionsWithPages, -} from "./constants"; -import { OrganicResult } from "./results"; +} from "./constants.js"; +import { OrganicResult } from "./results/index.js"; import { decodeResponse, prepareRequestConfig, type SearchResultTypeFromParser, safeGetFetch, -} from "./utils"; +} from "./utils.js"; export async function search( searchOptions: SearchOptions, diff --git a/packages/google-sr/src/utils.ts b/packages/google-sr/src/utils.ts index 94dc928..98e9075 100644 --- a/packages/google-sr/src/utils.ts +++ b/packages/google-sr/src/utils.ts @@ -3,8 +3,8 @@ import type { ResultParser, ResultTypes, SearchOptions, -} from "./constants"; -import { GOOGLE_SEARCH_URL } from "./constants"; +} from "./constants.js"; +import { GOOGLE_SEARCH_URL } from "./constants.js"; const baseHeaders = { Accept: "text/html", diff --git a/packages/google-sr/tests/results.test.ts b/packages/google-sr/tests/results.test.ts index 3735d97..cb8cc90 100644 --- a/packages/google-sr/tests/results.test.ts +++ b/packages/google-sr/tests/results.test.ts @@ -9,7 +9,7 @@ import { TimeResult, TranslateResult, UnitConversionResult, -} from "../src"; +} from "../src/index.js"; // Live tests require querying google, which can lead to rate limiting or blocking. // on development machines, we run live tests only if explicitly enabled diff --git a/packages/google-sr/tests/search.test.ts b/packages/google-sr/tests/search.test.ts index ed279e9..cf30d14 100644 --- a/packages/google-sr/tests/search.test.ts +++ b/packages/google-sr/tests/search.test.ts @@ -1,6 +1,6 @@ import { afterEach, describe, expect, it } from "vitest"; -import { OrganicResult, ResultTypes } from "../src"; -import { search, searchWithPages } from "../src/search"; +import { OrganicResult, ResultTypes } from "../src/index.js"; +import { search, searchWithPages } from "../src/search.js"; // Live tests require querying google, which can lead to rate limiting or blocking. // on development machines, we run live tests only if explicitly enabled diff --git a/packages/google-sr/tests/utils.test.ts b/packages/google-sr/tests/utils.test.ts index 37a60eb..f4b8eee 100644 --- a/packages/google-sr/tests/utils.test.ts +++ b/packages/google-sr/tests/utils.test.ts @@ -5,7 +5,7 @@ import { prepareRequestConfig, safeGetFetch, throwNoCheerioError, -} from "../src/utils"; +} from "../src/utils.js"; function createMockResponse(bytes: number[]): Response { const buffer = new Uint8Array(bytes); diff --git a/packages/google-sr/tsup.config.ts b/packages/google-sr/tsup.config.ts index 340312a..f3b6e6c 100644 --- a/packages/google-sr/tsup.config.ts +++ b/packages/google-sr/tsup.config.ts @@ -1,3 +1,3 @@ -import { createTsupConfig } from "../../tsup.config"; +import { createTsupConfig } from "../../tsup.config.js"; export default [createTsupConfig()]; diff --git a/packages/google-that/.npmignore b/packages/google-that/.npmignore deleted file mode 100644 index b5d83e2..0000000 --- a/packages/google-that/.npmignore +++ /dev/null @@ -1,13 +0,0 @@ - -# Stop npm from publishing ts files -src - -# Typescript -tsup.config.ts -tsconfig.json - -# tools -.turbo - -# Ignore changelog -CHANGELOG.md \ No newline at end of file diff --git a/packages/google-that/package.json b/packages/google-that/package.json index 5d6a02d..0895fd5 100644 --- a/packages/google-that/package.json +++ b/packages/google-that/package.json @@ -1,40 +1,47 @@ { - "name": "google-that", - "version": "1.1.1", - "description": "CLI tool to scrape google search results without a api key", - "repository": "https://github.com/typicalninja/google-sr", - "homepage": "https://github.com/typicalninja/google-sr", - "exports": null, - "bin": "./dist/index.js", - "type": "module", - "scripts": { - "build": "tsup", - "dev": "tsx src/index.ts" - }, - "keywords": [ - "google-sr", - "gsr", - "google", - "googlesr", - "search", - "google-search", - "googlesearch", - "scraping", - "cli" - ], - "author": "typicalninja", - "license": "Apache-2.0", - "dependencies": { - "@types/node": "^24.0.10", - "google-sr": "workspace:*", - "yargs": "^18.0.0" - }, - "engines": { - "node": ">=20.0.0", - "pnpm": ">=10.13.1" - }, - "devDependencies": { - "@types/yargs": "^17.0.33", - "tsx": "^4.20.3" - } + "name": "google-that", + "version": "1.1.1", + "description": "CLI tool to scrape google search results without a api key", + "author": "typicalninja", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "git+https://github.com/typicalninja/google-sr.git" + }, + "homepage": "https://github.com/typicalninja/google-sr", + "exports": null, + "bin": "./dist/index.js", + "type": "module", + "scripts": { + "build": "tsup", + "dev": "tsx src/index.ts" + }, + "engines": { + "node": ">=20.0.0", + "pnpm": ">=10.13.1" + }, + "dependencies": { + "google-sr": "workspace:*", + "yargs": "^18.0.0" + }, + "devDependencies": { + "@types/node": "^24.0.10", + "@types/yargs": "^17.0.33", + "tsx": "^4.20.3" + }, + "files": [ + "dist/", + "README.md" + ], + "keywords": [ + "google-sr", + "gsr", + "google", + "googlesr", + "search", + "google-search", + "googlesearch", + "scraping", + "cli" + ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 474bb67..1befec9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -83,9 +83,6 @@ importers: '@vitest/ui': specifier: 3.2.4 version: 3.2.4(vitest@3.2.4) - is-ci: - specifier: 4.1.0 - version: 4.1.0 vitest: specifier: ^3.2.4 version: 3.2.4(@types/node@24.0.10)(@vitest/ui@3.2.4)(jiti@2.4.2)(tsx@4.20.3)(yaml@2.8.0) @@ -94,9 +91,6 @@ importers: packages/google-that: dependencies: - '@types/node': - specifier: ^24.0.10 - version: 24.0.10 google-sr: specifier: workspace:* version: link:../google-sr @@ -104,6 +98,9 @@ importers: specifier: ^18.0.0 version: 18.0.0 devDependencies: + '@types/node': + specifier: ^24.0.10 + version: 24.0.10 '@types/yargs': specifier: ^17.0.33 version: 17.0.33