Skip to content

Commit e09168b

Browse files
committed
refactor: split into multiple packages + TS rewrite
Packages: - `@apify/consts` - `@apify/datastructures` - `@apify/git` - `@apify/hubspot_client` - `@apify/input_schema` - `@apify/log` - `@apify/markdown` - `@apify/salesforce_client` - `@apify/utilities` Other notable changes: - uses named exports except `log` where we keep the default export for logger instance - removes `underscore` from most of the packages (except salesforce/hubspot clients) - removed `startsWith` polyfill and `newPromise` method - `truncate` method is duplicated so the `log` package does not depend on `utilities` (as those bring a lot of 3rd party deps) TODO: - [ ] review the split into packages from dependency point of view - [ ] rewrite CI publishing via lerna (it will be broken now) Closes #131
1 parent aae45d0 commit e09168b

File tree

104 files changed

+3041
-2690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+3041
-2690
lines changed

.github/workflows/check.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
strategy:
16+
fail-fast: false
1617
matrix:
17-
node-version: [10, 12, 14]
18+
node-version: [12, 14, 15, 16]
1819

1920
steps:
2021
-
@@ -33,6 +34,9 @@ jobs:
3334
node_modules
3435
build
3536
key: cache-${{ github.run_id }}-v14
37+
-
38+
name: Upgrade NPM to have workspaces support
39+
run: npm i -G npm@latest
3640
-
3741
name: Install Dependencies
3842
run: npm install

.github/workflows/release.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO needs lerna rewrite
12
name: Check & Release
23

34
on:
@@ -18,7 +19,7 @@ jobs:
1819

1920
strategy:
2021
matrix:
21-
node-version: [10, 12, 14]
22+
node-version: [12, 14, 15, 16]
2223

2324
steps:
2425
-
@@ -37,6 +38,9 @@ jobs:
3738
node_modules
3839
build
3940
key: cache-${{ github.run_id }}-v14
41+
-
42+
name: Upgrade NPM to have workspaces support
43+
run: npm i -G npm@latest
4044
-
4145
name: Install Dependencies
4246
run: npm install

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
build
1+
dist
22
docs
33
node_modules
44
*.log
@@ -12,4 +12,3 @@ pids
1212
.idea
1313
yarn.lock
1414
package-lock.json
15-
types/

lerna.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"packages": [
3+
"packages/*"
4+
],
5+
"useWorkspaces": true,
6+
"version": "0.7.7"
7+
}

package.json

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "apify-shared",
3+
"private": true,
34
"version": "0.7.7",
45
"description": "Tools and constants shared across Apify projects.",
56
"main": "build/index.js",
@@ -10,71 +11,70 @@
1011
"author": {
1112
"name": "Apify",
1213
"email": "support@apify.com",
13-
"url": "https://www.apify.com"
14+
"url": "https://apify.com"
1415
},
1516
"contributors": [
1617
"Jan Curn <jan@apify.com>",
1718
"Marek Trunkát <marek@apify.com>"
1819
],
1920
"license": "Apache-2.0",
21+
"workspaces": [
22+
"packages/*"
23+
],
2024
"repository": {
2125
"type": "git",
22-
"url": "git+https://github.com/apifytech/apify-shared-js"
26+
"url": "git+https://github.com/apify/apify-shared-js"
2327
},
2428
"bugs": {
25-
"url": "https://github.com/apifytech/apify-shared-js/issues"
29+
"url": "https://github.com/apify/apify-shared-js/issues"
2630
},
2731
"homepage": "https://apify.com",
2832
"scripts": {
29-
"build": "rm -rf build types && babel src --out-dir build && cp src/*.json build && tsc ./src/*.js --allowJs --declaration --emitDeclarationOnly --declarationDir build --skipLibCheck",
30-
"build-doc": "npm run clean && npm run build && node ./node_modules/jsdoc/jsdoc.js --package ./package.json -c ./jsdoc/conf.json -d docs",
31-
"build-local-dev": "npm run build && cp package.json build && pushd build/ && npm i && popd",
32-
"test": "npm run build && mocha --timeout 5000 --require @babel/register --recursive",
33-
"test-cov": "npm run build && babel-node node_modules/isparta/bin/isparta cover --report text --report html node_modules/mocha/bin/_mocha -- --reporter dot",
33+
"clean": "lerna run clean",
34+
"build": "lerna run build",
35+
"test": "jest --silent",
36+
"test-cov": "jest --coverage",
3437
"prepublishOnly": "(test $CI || (echo \"Publishing is reserved to CI!\"; exit 1))",
35-
"clean": "rm -rf build docs types",
3638
"lint": "npm run build && eslint src test",
3739
"lint:fix": "eslint src test --fix"
3840
},
39-
"dependencies": {
40-
"@hubspot/api-client": "^3.4.1",
41-
"axios": "^0.21.1",
42-
"chalk": "^4.0.0",
43-
"cherow": "^1.6.9",
44-
"clone": "^2.1.1",
45-
"countries-list": "^2.6.1",
46-
"create-hmac": "^1.1.7",
47-
"git-url-parse": "^11.4.4",
48-
"is-buffer": "^2.0.5",
49-
"marked": "^2.0.0",
50-
"match-all": "^1.2.6",
51-
"moment": "^2.29.1",
52-
"request": "^2.88.0",
53-
"underscore": "^1.11.0",
54-
"url": "^0.11.0"
41+
"jest": {
42+
"testTimeout": 30000,
43+
"preset": "ts-jest",
44+
"testEnvironment": "node",
45+
"collectCoverage": false,
46+
"collectCoverageFrom": [
47+
"<rootDir>/packages/*/src/**/*.ts"
48+
],
49+
"moduleNameMapper": {
50+
"@apify/(.*)": "<rootDir>/packages/$1/src"
51+
},
52+
"modulePathIgnorePatterns": [
53+
"dist/package.json",
54+
"<rootDir>/package.json"
55+
],
56+
"globals": {
57+
"ts-jest": {
58+
"tsconfig": "test/tsconfig.json"
59+
}
60+
}
5561
},
5662
"devDependencies": {
5763
"@apify/eslint-config": "^0.1.3",
58-
"@babel/cli": "^7.12.13",
59-
"@babel/core": "^7.12.13",
60-
"@babel/plugin-proposal-object-rest-spread": "^7.12.13",
61-
"@babel/preset-env": "^7.12.13",
62-
"@babel/register": "^7.12.13",
63-
"ajv": "^6.12.6",
64-
"apify-jsdoc-template": "github:apifytech/apify-jsdoc-template",
65-
"babel-plugin-add-module-exports": "^1.0.4",
66-
"chai": "^4.2.0",
67-
"chai-as-promised": "^7.1.1",
64+
"@types/git-url-parse": "^9.0.0",
65+
"@types/jest": "^26.0.23",
66+
"@types/marked": "^2.0.2",
67+
"@types/node": "^14.14.41",
68+
"@types/underscore": "^1.11.2",
6869
"deploy-web-to-s3": "^1.3.0",
6970
"eslint": "^7.19.0",
70-
"isparta": "^4.1.1",
71-
"istanbul": "0.4.5",
72-
"jsdoc": "^3.6.6",
73-
"jsdoc-export-default-interop": "^0.3.1",
74-
"mocha": "^7.2.0",
71+
"jest": "^26.6.3",
72+
"lerna": "^4.0.0",
7573
"nock": "^13.0.7",
76-
"sinon": "^9.2.4",
7774
"strip-ansi": "^6.0.0",
78-
"typescript": "^4.2.3"
75+
"ts-jest": "^26.5.5",
76+
"ts-node": "^9.1.1",
77+
"typescript": "^4.2.4",
78+
"underscore": "^1.13.1"
7979
}
8080
}

packages/consts/package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "@apify/consts",
3+
"version": "1.0.0",
4+
"description": "Tools and constants shared across Apify projects.",
5+
"main": "dist/index.js",
6+
"module": "dist/index.mjs",
7+
"typings": "dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": "./dist/index.mjs",
11+
"require": "./dist/index.js"
12+
}
13+
},
14+
"keywords": [
15+
"apify"
16+
],
17+
"author": {
18+
"name": "Apify",
19+
"email": "support@apify.com",
20+
"url": "https://apify.com"
21+
},
22+
"contributors": [
23+
"Jan Curn <jan@apify.com>",
24+
"Marek Trunkát <marek@apify.com>"
25+
],
26+
"license": "Apache-2.0",
27+
"repository": {
28+
"type": "git",
29+
"url": "git+https://github.com/apify/apify-shared-js"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/apify/apify-shared-js/issues"
33+
},
34+
"homepage": "https://apify.com",
35+
"scripts": {
36+
"build": "npm run clean && npm run compile && npm run copy",
37+
"postbuild": "yarn gen-esm-wrapper dist/index.js dist/index.mjs",
38+
"clean": "rimraf ./dist",
39+
"compile": "tsc -p tsconfig.build.json",
40+
"copy": "ts-node -T ../../scripts/copy.ts"
41+
},
42+
"publishConfig": {
43+
"access": "public"
44+
},
45+
"dependencies": {},
46+
"devDependencies": {
47+
"gen-esm-wrapper": "^1.1.1"
48+
}
49+
}

src/consts.js renamed to packages/consts/src/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ export const ENV_VARS = {
376376
FACT: 'APIFY_FACT',
377377
DEDICATED_CPUS: 'APIFY_DEDICATED_CPUS',
378378
SDK_LATEST_VERSION: 'APIFY_SDK_LATEST_VERSION',
379+
INTERNAL_PORT: 'APIFY_INTERNAL_PORT',
379380

380381
// Deprecated, keep them for backward compatibility:
381382
ACT_ID: 'APIFY_ACT_ID',

packages/consts/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './consts';
2+
export * from './regexs';

src/regexs.js renamed to packages/consts/src/regexs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const TWITTER_REGEX = /^@[a-z0-9_]{1,15}$/i;
5252
export const GITHUB_REGEX = new RegExp(`^${GITHUB_REGEX_STR}$`, 'i');
5353

5454
// @TODO: Discontinue usage of this regexps, in favor of HTTP_URL_REGEX
55-
export const URL_REGEX = /^(http:\/\/|https:\/\/)/i;
55+
export const URL_REGEX = /^https?:\/\//i;
5656

5757
// Inspired by https://gist.github.com/dperini/729294, but doesn't match FTP URLs
5858
/* eslint-disable */
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.build.json",
3+
"compilerOptions": {
4+
"outDir": "./dist"
5+
},
6+
"include": ["src/**/*"]
7+
}

0 commit comments

Comments
 (0)