Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: esm builds #323

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ apify_storage
crawlee_storage
storage
.turbo
.tshy
.tshy-build
18,860 changes: 0 additions & 18,860 deletions package-lock.json

This file was deleted.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"name": "apify-sdk-js",
"private": true,
"description": "Apify SDK monorepo",
"workspaces": [
"packages/*",
"packages/actor-scraper/*"
],
"keywords": [
"apify",
"headless",
Expand Down Expand Up @@ -55,6 +51,7 @@
"@apify/tsconfig": "^0.1.0",
"@commitlint/config-conventional": "^19.2.2",
"@playwright/browser-chromium": "^1.46.0",
"@total-typescript/tsconfig": "^1.0.4",
"@types/content-type": "^1.1.8",
"@types/fs-extra": "^11.0.4",
"@types/node": "^22.1.0",
Expand All @@ -74,11 +71,17 @@
"playwright": "^1.46.0",
"puppeteer": "^22.15.0",
"rimraf": "^6.0.1",
"tshy": "^3.0.2",
"tsx": "^4.16.5",
"turbo": "2.1.1",
"typescript": "~5.5.4",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.0.5"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1",
"pnpm": {
"patchedDependencies": {
"@crawlee/[email protected]": "patches/@[email protected]"
}
}
}
1 change: 1 addition & 0 deletions packages/actor-scraper/puppeteer-scraper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"@apify/scraper-tools": "^1.1.1",
"@crawlee/puppeteer": "^3.8.2",
"@crawlee/utils": "^3.11.2",
"apify": "^3.1.8",
"idcac-playwright": "^0.1.2",
"puppeteer": "*"
Expand Down
1 change: 1 addition & 0 deletions packages/actor-scraper/web-scraper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "dist/main.js",
"type": "module",
"dependencies": {
"@apify/log": "^2.5.5",
"@apify/scraper-tools": "^1.1.1",
"@crawlee/puppeteer": "^3.8.2",
"apify": "^3.1.8",
Expand Down
41 changes: 27 additions & 14 deletions packages/apify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@
"engines": {
"node": ">=16.0.0"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./package.json": "./package.json"
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"files": [
"dist"
],
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"keywords": [
"apify",
Expand Down Expand Up @@ -44,11 +59,9 @@
},
"homepage": "https://docs.apify.com/sdk/js",
"scripts": {
"build": "npm run clean && npm run compile && npm run copy && npm run fixApifyExport",
"build": "npm run clean && npm run compile",
"clean": "rimraf ./dist",
"compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./dist/index.js ./dist/index.mjs",
"copy": "tsx ../../scripts/copy.ts --readme=local",
"fixApifyExport": "tsx ../../scripts/temp_fix_apify_exports.ts"
"compile": "tshy"
},
"publishConfig": {
"access": "public"
Expand All @@ -64,9 +77,9 @@
"@crawlee/utils": "^3.9.0",
"apify-client": "^2.9.0",
"fs-extra": "^11.2.0",
"ow": "^0.28.2",
"ow": "^2.0.0",
"semver": "^7.5.4",
"tslib": "^2.6.2",
"ws": "^8.18.0"
}
}
}
16 changes: 8 additions & 8 deletions packages/apify/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import {
ActorRun as ClientActorRun,
ApifyClient,
} from 'apify-client';
import ow from 'ow';

import { Configuration } from './configuration';
import { KeyValueStore } from './key_value_store';
import { PlatformEventManager } from './platform_event_manager';
import type { ProxyConfigurationOptions } from './proxy_configuration';
import { ProxyConfiguration } from './proxy_configuration';
import { checkCrawleeVersion, logSystemInfo, printOutdatedSdkWarning } from './utils';
import { Configuration } from './configuration.js';
import { KeyValueStore } from './key_value_store.js';
import ow from './ow.js';
import { PlatformEventManager } from './platform_event_manager.js';
import type { ProxyConfigurationOptions } from './proxy_configuration.js';
import { ProxyConfiguration } from './proxy_configuration.js';
import { checkCrawleeVersion, logSystemInfo, printOutdatedSdkWarning } from './utils.js';

/**
* `Actor` class serves as an alternative approach to the static helpers exported from the package. It allows to pass configuration
Expand Down Expand Up @@ -1808,7 +1808,7 @@ export interface OpenStorageOptions {
forceCloud?: boolean;
}

export { ClientActorRun as ActorRun };
export type { ClientActorRun as ActorRun };

/**
* Exit codes for the Actor process.
Expand Down
38 changes: 29 additions & 9 deletions packages/apify/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
export * from './actor';
export * from './configuration';
export * from './proxy_configuration';
export * from './platform_event_manager';
export * from './key_value_store';
export * from './actor.js';
export * from './configuration.js';
export * from './proxy_configuration.js';
export * from './platform_event_manager.js';
export * from './key_value_store.js';
export {
Dataset, DatasetDataOptions, DatasetIteratorOptions, DatasetConsumer, DatasetMapper, DatasetReducer, DatasetOptions, DatasetContent,
RequestQueue, QueueOperationInfo, RequestQueueOperationOptions, RequestQueueOptions,
KeyConsumer, KeyValueStoreOptions, RecordOptions, KeyValueStoreIteratorOptions, log, Log, LoggerOptions, LogLevel, Logger, LoggerJson, LoggerText,
Dataset,
type DatasetDataOptions,
type DatasetIteratorOptions,
type DatasetConsumer,
type DatasetMapper,
type DatasetReducer,
type DatasetOptions,
type DatasetContent,
RequestQueue,
type QueueOperationInfo,
type RequestQueueOperationOptions,
type RequestQueueOptions,
type KeyConsumer,
type KeyValueStoreOptions,
type RecordOptions,
type KeyValueStoreIteratorOptions,
log,
Log,
type LoggerOptions,
LogLevel,
Logger,
LoggerJson,
LoggerText,
} from '@crawlee/core';
export { ApifyClient, ApifyClientOptions } from 'apify-client';
export { ApifyClient, type ApifyClientOptions } from 'apify-client';
2 changes: 1 addition & 1 deletion packages/apify/src/key_value_store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StorageManagerOptions } from '@crawlee/core';
import { KeyValueStore as CoreKeyValueStore } from '@crawlee/core';

import type { Configuration } from './configuration';
import type { Configuration } from './configuration.js';

// @ts-ignore newer crawlee versions already declare this method in core
const { getPublicUrl } = CoreKeyValueStore.prototype;
Expand Down
4 changes: 4 additions & 0 deletions packages/apify/src/ow-cjs.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const ow = require('ow');

export default ow;
5 changes: 5 additions & 0 deletions packages/apify/src/ow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://github.com/isaacs/tshy?tab=readme-ov-file#commonjs-dialect-polyfills
// @ts-ignore
import ow from 'ow';

export default ow;
2 changes: 1 addition & 1 deletion packages/apify/src/platform_event_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { betterClearInterval } from '@apify/utilities';
import { EventType, EventManager } from '@crawlee/core';
import { WebSocket } from 'ws';

import { Configuration } from './configuration';
import { Configuration } from './configuration.js';

/**
* Gets an instance of a Node.js'
Expand Down
6 changes: 3 additions & 3 deletions packages/apify/src/proxy_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
} from '@crawlee/core';
import { gotScraping } from '@crawlee/utils';
import type { UserProxy } from 'apify-client';
import ow from 'ow';

import { Actor } from './actor';
import { Configuration } from './configuration';
import { Actor } from './actor.js';
import { Configuration } from './configuration.js';
import ow from './ow.js';

// https://docs.apify.com/proxy/datacenter-proxy#username-parameters
const MAX_SESSION_ID_LENGTH = 50;
Expand Down
3 changes: 0 additions & 3 deletions packages/apify/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { normalize } from 'node:path';

import { APIFY_ENV_VARS } from '@apify/consts';
import log from '@apify/log';
// @ts-expect-error if we enable resolveJsonModule, we end up with `src` folder in `dist`
import { version as crawleeVersion } from '@crawlee/core/package.json';
// @ts-expect-error if we enable resolveJsonModule, we end up with `src` folder in `dist`
import { version as apifyClientVersion } from 'apify-client/package.json';
import { pathExistsSync, readJSONSync } from 'fs-extra';
import semver from 'semver';

// @ts-expect-error if we enable resolveJsonModule, we end up with `src` folder in `dist`
import { version as apifyVersion } from '../package.json';

/**
Expand Down
9 changes: 0 additions & 9 deletions packages/apify/tsconfig.build.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/apify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
44 changes: 31 additions & 13 deletions packages/scraper-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
"name": "@apify/scraper-tools",
"version": "1.1.4",
"description": "Tools shared by Apify actor-scrapers.",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"type": "module",
"files": [
"dist"
],
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"author": {
Expand All @@ -25,10 +28,9 @@
},
"homepage": "https://github.com/apify/apify-sdk-js",
"scripts": {
"build": "npm run clean && npm run compile && npm run copy",
"clean": "rimraf ./dist",
"compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./dist/index.js ./dist/index.mjs",
"copy": "tsx ../../scripts/copy.ts --readme=false"
"build": "npm run clean && npm run compile",
"compile": "tshy",
"clean": "rimraf ./dist"
},
"publishConfig": {
"access": "public"
Expand All @@ -44,14 +46,14 @@
"@crawlee/core": "^3.8.2",
"@crawlee/types": "^3.8.2",
"@crawlee/utils": "^3.8.2",
"apify": "^3.1.8"
"apify": "workspace:^"
},
"peerDependencies": {
"@crawlee/browser-pool": "^3.8.2",
"@crawlee/core": "^3.8.2",
"@crawlee/types": "^3.8.2",
"@crawlee/utils": "^3.8.2",
"apify": "^3.1.8"
"apify": "workspace:^"
},
"peerDependenciesMeta": {
"@crawlee/puppeteer": {
Expand All @@ -60,5 +62,21 @@
"@crawlee/playwright": {
"optional": true
}
}
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js"
}
3 changes: 3 additions & 0 deletions packages/scraper-tools/src/ajv-cjs.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Ajv from 'ajv';

export default Ajv;
6 changes: 6 additions & 0 deletions packages/scraper-tools/src/ajv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import AjvModule from 'ajv';

// @ts-ignore
const Ajv = AjvModule.default;

export default Ajv;
4 changes: 2 additions & 2 deletions packages/scraper-tools/src/browser_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import log from '@apify/log';
import type { CommonPage } from '@crawlee/browser-pool';
import { Actor } from 'apify';

import { RESOURCE_LOAD_ERROR_MESSAGE, SNAPSHOT } from './consts';
import { createRandomHash } from './tools';
import { RESOURCE_LOAD_ERROR_MESSAGE, SNAPSHOT } from './consts.js';
import { createRandomHash } from './tools.js';

export interface Page extends CommonPage {
exposeFunction(name: string, callback: () => unknown): Promise<void>;
Expand Down
8 changes: 4 additions & 4 deletions packages/scraper-tools/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { Actor } from 'apify';
import type { MediaType } from 'content-type';
import contentTypeParser from 'content-type';

import type { SnapshotOptions } from './browser_tools';
import { saveSnapshot } from './browser_tools';
import { META_KEY } from './consts';
import type { RequestMetadata } from './tools';
import type { SnapshotOptions } from './browser_tools.js';
import { saveSnapshot } from './browser_tools.js';
import { META_KEY } from './consts.js';
import type { RequestMetadata } from './tools.js';

export interface CrawlerSetupOptions {
rawInput: string;
Expand Down
Loading