apify-cli 0.19.2-beta.4 → 0.19.2-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-cli",
3
- "version": "0.19.2-beta.4",
3
+ "version": "0.19.2-beta.6",
4
4
  "description": "Apify command-line interface helps you create, develop, build and run Apify actors, and manage the Apify cloud platform.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@ const { replaceSecretsValue } = require('../lib/secrets');
16
16
  const {
17
17
  getLocalUserInfo, purgeDefaultQueue, purgeDefaultKeyValueStore,
18
18
  purgeDefaultDataset, getLocalConfigOrThrow, getNpmCmd, checkIfStorageIsEmpty,
19
- detectLocalActorLanguage, isPythonVersionSupported, getPythonCommand, isNodeVersionSupported,
19
+ detectLocalActorLanguage, isPythonVersionSupported, getPythonCommand, isNodeVersionSupported, getLocalStorageDir,
20
20
  } = require('../lib/utils');
21
21
 
22
22
  class RunCommand extends ApifyCommand {
@@ -29,9 +29,12 @@ class RunCommand extends ApifyCommand {
29
29
  const packageJsonPath = path.join(cwd, 'package.json');
30
30
  const mainPyPath = path.join(cwd, 'src/__main__.py');
31
31
 
32
+ const projectType = ProjectAnalyzer.getProjectType(cwd);
33
+ const actualStoragePath = getLocalStorageDir();
34
+
32
35
  const packageJsonExists = fs.existsSync(packageJsonPath);
33
36
  const mainPyExists = fs.existsSync(mainPyPath);
34
- const isScrapyProject = ProjectAnalyzer.getProjectType(cwd) === PROJECT_TYPES.SCRAPY;
37
+ const isScrapyProject = projectType === PROJECT_TYPES.SCRAPY;
35
38
 
36
39
  if (!packageJsonExists && !mainPyExists && !isScrapyProject) {
37
40
  throw new Error(
@@ -40,25 +43,43 @@ class RunCommand extends ApifyCommand {
40
43
  );
41
44
  }
42
45
 
43
- if (fs.existsSync(LEGACY_LOCAL_STORAGE_DIR) && !fs.existsSync(DEFAULT_LOCAL_STORAGE_DIR)) {
44
- fs.renameSync(LEGACY_LOCAL_STORAGE_DIR, DEFAULT_LOCAL_STORAGE_DIR);
45
- warning("The legacy 'apify_storage' directory was renamed to 'storage' to align it with Apify SDK v3."
46
+ if (fs.existsSync(LEGACY_LOCAL_STORAGE_DIR) && !fs.existsSync(actualStoragePath)) {
47
+ fs.renameSync(LEGACY_LOCAL_STORAGE_DIR, actualStoragePath);
48
+ warning(`The legacy 'apify_storage' directory was renamed to '${actualStoragePath}' to align it with Apify SDK v3.`
46
49
  + ' Contents were left intact.');
47
50
  }
48
51
 
52
+ let CRAWLEE_PURGE_ON_START = '0';
53
+
49
54
  // Purge stores
50
55
  if (flags.purge) {
51
- await Promise.all([purgeDefaultQueue(), purgeDefaultKeyValueStore(), purgeDefaultDataset()]);
52
- info('All default local stores were purged.');
56
+ switch (projectType) {
57
+ case PROJECT_TYPES.CRAWLEE: {
58
+ CRAWLEE_PURGE_ON_START = '1';
59
+ break;
60
+ }
61
+ case PROJECT_TYPES.PRE_CRAWLEE_APIFY_SDK: {
62
+ await Promise.all([purgeDefaultQueue(), purgeDefaultKeyValueStore(), purgeDefaultDataset()]);
63
+ info('All default local stores were purged.');
64
+ break;
65
+ }
66
+ default: {
67
+ // TODO: Python SDK too
68
+ }
69
+ }
53
70
  }
71
+
72
+ // TODO: deprecate these flags
54
73
  if (flags.purgeQueue) {
55
74
  await purgeDefaultQueue();
56
75
  info('Default local request queue was purged.');
57
76
  }
77
+
58
78
  if (flags.purgeDataset) {
59
79
  await purgeDefaultDataset();
60
80
  info('Default local dataset was purged.');
61
81
  }
82
+
62
83
  if (flags.purgeKeyValueStore) {
63
84
  await purgeDefaultKeyValueStore();
64
85
  info('Default local key-value store was purged.');
@@ -74,7 +95,9 @@ class RunCommand extends ApifyCommand {
74
95
 
75
96
  // Attach env vars from local config files
76
97
  const localEnvVars = {
77
- [APIFY_ENV_VARS.LOCAL_STORAGE_DIR]: DEFAULT_LOCAL_STORAGE_DIR,
98
+ [APIFY_ENV_VARS.LOCAL_STORAGE_DIR]: actualStoragePath,
99
+ CRAWLEE_STORAGE_DIR: actualStoragePath,
100
+ CRAWLEE_PURGE_ON_START,
78
101
  };
79
102
  if (proxy && proxy.password) localEnvVars[APIFY_ENV_VARS.PROXY_PASSWORD] = proxy.password;
80
103
  if (userId) localEnvVars[APIFY_ENV_VARS.USER_ID] = userId;
package/src/lib/consts.js CHANGED
@@ -25,6 +25,8 @@ exports.LANGUAGE = {
25
25
 
26
26
  exports.PROJECT_TYPES = {
27
27
  SCRAPY: 'scrapy',
28
+ CRAWLEE: 'crawlee',
29
+ PRE_CRAWLEE_APIFY_SDK: 'apify',
28
30
  UNKNOWN: 'unknown',
29
31
  };
30
32
 
@@ -1,4 +1,6 @@
1
1
  const { PROJECT_TYPES } = require('./consts');
2
+ const { CrawleeAnalyzer } = require('./projects/CrawleeAnalyzer');
3
+ const { OldApifySDKAnalyzer } = require('./projects/OldApifySDKAnalyzer');
2
4
  const { ScrapyProjectAnalyzer } = require('./scrapy-wrapper/ScrapyProjectAnalyzer');
3
5
 
4
6
  const analyzers = [
@@ -6,6 +8,14 @@ const analyzers = [
6
8
  type: PROJECT_TYPES.SCRAPY,
7
9
  analyzer: ScrapyProjectAnalyzer,
8
10
  },
11
+ {
12
+ type: PROJECT_TYPES.CRAWLEE,
13
+ analyzer: CrawleeAnalyzer,
14
+ },
15
+ {
16
+ type: PROJECT_TYPES.PRE_CRAWLEE_APIFY_SDK,
17
+ analyzer: OldApifySDKAnalyzer,
18
+ },
9
19
  ];
10
20
 
11
21
  class ProjectAnalyzer {
@@ -17,6 +27,7 @@ class ProjectAnalyzer {
17
27
 
18
28
  return a.analyzer.isApplicable(pathname);
19
29
  });
30
+
20
31
  return analyzer?.type || PROJECT_TYPES.UNKNOWN;
21
32
  }
22
33
  }
@@ -0,0 +1,37 @@
1
+ const { existsSync, readFileSync } = require('fs');
2
+ const { join } = require('path');
3
+
4
+ const CRAWLEE_PACKAGES = [
5
+ 'crawlee',
6
+ '@crawlee/core',
7
+ '@crawlee/puppeteer',
8
+ '@crawlee/playwright',
9
+ '@crawlee/cheerio',
10
+ '@crawlee/jsdom',
11
+ '@crawlee/linkedom',
12
+ '@crawlee/http',
13
+ '@crawlee/browser',
14
+ '@crawlee/basic',
15
+ ];
16
+
17
+ class CrawleeAnalyzer {
18
+ static isApplicable(pathname) {
19
+ const hasPackageJson = existsSync(join(pathname, 'package.json'));
20
+
21
+ if (!hasPackageJson) {
22
+ return false;
23
+ }
24
+
25
+ const packageJson = readFileSync(join(pathname, 'package.json'), 'utf8');
26
+
27
+ try {
28
+ const packageJsonParsed = JSON.parse(packageJson);
29
+
30
+ return CRAWLEE_PACKAGES.some((pkg) => packageJsonParsed?.dependencies?.[pkg] !== undefined);
31
+ } catch (err) {
32
+ return false;
33
+ }
34
+ }
35
+ }
36
+
37
+ exports.CrawleeAnalyzer = CrawleeAnalyzer;
@@ -0,0 +1,61 @@
1
+ const { existsSync, readFileSync } = require('fs');
2
+ const { join } = require('path');
3
+
4
+ const { lt } = require('semver');
5
+
6
+ const VERSION_WHEN_APIFY_MOVED_TO_CRAWLEE = '3.0.0';
7
+ const CRAWLEE_PACKAGES = [
8
+ 'crawlee',
9
+ '@crawlee/core',
10
+ '@crawlee/puppeteer',
11
+ '@crawlee/playwright',
12
+ '@crawlee/cheerio',
13
+ '@crawlee/jsdom',
14
+ '@crawlee/linkedom',
15
+ '@crawlee/http',
16
+ '@crawlee/browser',
17
+ '@crawlee/basic',
18
+ ];
19
+
20
+ class OldApifySDKAnalyzer {
21
+ static isApplicable(pathname) {
22
+ const hasPackageJson = existsSync(join(pathname, 'package.json'));
23
+
24
+ if (!hasPackageJson) {
25
+ return false;
26
+ }
27
+
28
+ const packageJson = readFileSync(join(pathname, 'package.json'), 'utf8');
29
+
30
+ try {
31
+ const packageJsonParsed = JSON.parse(packageJson);
32
+
33
+ // If they have crawlee as a dependency, likely to use crawlee
34
+ if (CRAWLEE_PACKAGES.some((pkg) => packageJsonParsed?.dependencies?.[pkg] !== undefined)) {
35
+ return false;
36
+ }
37
+
38
+ const apifyVersion = packageJsonParsed?.dependencies?.apify;
39
+ if (!apifyVersion) {
40
+ return false;
41
+ }
42
+
43
+ // We cannot infer
44
+ if (apifyVersion === '*') {
45
+ return false;
46
+ }
47
+
48
+ let actualVersion = apifyVersion;
49
+
50
+ if (apifyVersion.startsWith('~') || apifyVersion.startsWith('^')) {
51
+ actualVersion = apifyVersion.slice(1);
52
+ }
53
+
54
+ return lt(actualVersion, VERSION_WHEN_APIFY_MOVED_TO_CRAWLEE);
55
+ } catch (err) {
56
+ return false;
57
+ }
58
+ }
59
+ }
60
+
61
+ exports.OldApifySDKAnalyzer = OldApifySDKAnalyzer;
package/src/lib/utils.js CHANGED
@@ -80,7 +80,7 @@ const MIGRATED_APIFY_JSON_PROPERTIES = ['name', 'version', 'buildTag'];
80
80
  const getLocalStorageDir = () => {
81
81
  const envVar = APIFY_ENV_VARS.LOCAL_STORAGE_DIR;
82
82
 
83
- return process.env[envVar] || DEFAULT_LOCAL_STORAGE_DIR;
83
+ return process.env[envVar] || process.env.CRAWLEE_STORAGE_DIR || DEFAULT_LOCAL_STORAGE_DIR;
84
84
  };
85
85
  const getLocalKeyValueStorePath = (storeId) => {
86
86
  const envVar = ACTOR_ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID;