@sasjs/cli 4.12.15 → 4.12.16

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.
@@ -99,26 +99,36 @@ var internal_1 = require("../compile/internal");
99
99
  var config_2 = require("./internal/config");
100
100
  var getLaunchPageCode_1 = require("./internal/getLaunchPageCode");
101
101
  function build(target) {
102
+ var _a;
102
103
  return __awaiter(this, void 0, void 0, function () {
103
- var _a;
104
- return __generator(this, function (_b) {
105
- switch (_b.label) {
104
+ var macroCorePath, _b;
105
+ return __generator(this, function (_c) {
106
+ switch (_c.label) {
106
107
  case 0:
107
- _a = process.sasjsConstants.buildDestinationFolder;
108
- if (!_a) return [3 /*break*/, 2];
108
+ macroCorePath = process.sasjsConstants.macroCorePath;
109
+ if (macroCorePath === '') {
110
+ throw new Error("The @sasjs/core folder location is unknown.\n" +
111
+ "Check that @sasjs/core is a dependency in the package.json, and \n" +
112
+ "that the package has been installed.\n" +
113
+ "Alternatively populate environment variable 'macroCorePath' with\n" +
114
+ "the path to a local @sasjs/core package's root directory.");
115
+ }
116
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("@sasjs/core found at ".concat(macroCorePath));
117
+ _b = process.sasjsConstants.buildDestinationFolder;
118
+ if (!_b) return [3 /*break*/, 2];
109
119
  return [4 /*yield*/, (0, utils_1.folderExists)(process.sasjsConstants.buildDestinationFolder)];
110
120
  case 1:
111
- _a = !(_b.sent());
112
- _b.label = 2;
121
+ _b = !(_c.sent());
122
+ _c.label = 2;
113
123
  case 2:
114
- if (!_a) return [3 /*break*/, 4];
124
+ if (!_b) return [3 /*break*/, 4];
115
125
  return [4 /*yield*/, (0, compile_1.compile)(target)];
116
126
  case 3:
117
- _b.sent();
118
- _b.label = 4;
127
+ _c.sent();
128
+ _c.label = 4;
119
129
  case 4: return [4 /*yield*/, createFinalSasFiles(target)];
120
130
  case 5:
121
- _b.sent();
131
+ _c.sent();
122
132
  return [2 /*return*/];
123
133
  }
124
134
  });
@@ -245,7 +255,7 @@ function getBuildInfo(target, streamWeb) {
245
255
  case 8:
246
256
  buildVars = _a.sent();
247
257
  return [2 /*return*/, "\n/**\n * The appLoc represents the metadata or SAS Drive location of the app you\n * are about to deploy\n *\n * To set an alternative appLoc, simply populate the appLoc variable prior\n * to running this program, eg:\n *\n * %let apploc=/my/apploc;\n * %inc thisfile;\n *\n */\n\n%global appLoc;\n%let compiled_apploc=".concat(appLoc, ";\n%let appLoc=%sysfunc(coalescec(&appLoc,&compiled_apploc));\n\n\n").concat(serverType === utils_1.ServerType.Sas9
248
- ? "\n/**\n * The serverName represents the SAS 9 logical server context\n * There is no programmatic (SAS code) way to obtain this\n * So it is taken from the sasjsconfig file OR supplied at runtime, eg:\n * \n * %let apploc=/my/apploc;\n * %let serverName=SASAppDC;\n * %inc thisfile;\n * \n */\n\n%global serverName;\n%let compiled_serverName=".concat(serverName, ";\n%let serverName=%sysfunc(coalescec(&serverName,&compiled_serverName));\n")
258
+ ? "\n/**\n * The serverName represents the SAS 9 logical server context\n * There is no programmatic (SAS code) way to obtain this\n * So it is taken from the sasjsconfig file OR supplied at runtime, eg:\n *\n * %let apploc=/my/apploc;\n * %let serverName=SASAppDC;\n * %inc thisfile;\n *\n */\n\n%global serverName;\n%let compiled_serverName=".concat(serverName, ";\n%let serverName=%sysfunc(coalescec(&serverName,&compiled_serverName));\n")
249
259
  : '', "\n\n%let sasjs_clickmeservice=clickme;\n%let syscc=0;\noptions ps=max nonotes nosgen nomprint nomlogic nosource2 nosource noquotelenmax;\n/* user supplied build vars */\n").concat(buildVars, "\n/* user supplied build vars end */\n/* system macro dependencies for build process */\n").concat(dependenciesContent, "\n/* system macro dependencies for build process end*/\n/* system macros for build process */\n").concat((0, utils_1.removeHeader)(buildConfig), "\n/* system macros for build process end */\n")];
250
260
  }
251
261
  });
@@ -48,8 +48,9 @@ var setConstants = function (isLocal, target, configuration) {
48
48
  if (isLocal === void 0) { isLocal = true; }
49
49
  return __awaiter(void 0, void 0, void 0, function () {
50
50
  var buildOutputFolder, buildResultsFolder, homeDir, buildSourceFolder, buildSourceDbFolder, buildDestinationFolder, buildDestinationServicesFolder, buildDestinationTestFolder, buildDestinationJobsFolder, buildDestinationDbFolder, buildDestinationDocsFolder, macroCorePath, buildDestinationResultsFolder, buildDestinationResultsLogsFolder, sas9CredentialsError, invalidSasError, sas9GUID;
51
- return __generator(this, function (_a) {
52
- switch (_a.label) {
51
+ var _a;
52
+ return __generator(this, function (_b) {
53
+ switch (_b.label) {
53
54
  case 0:
54
55
  buildOutputFolder = (target === null || target === void 0 ? void 0 : target.sasjsBuildFolder) ||
55
56
  (configuration === null || configuration === void 0 ? void 0 : configuration.sasjsBuildFolder) ||
@@ -66,9 +67,15 @@ var setConstants = function (isLocal, target, configuration) {
66
67
  buildDestinationJobsFolder = path_1.default.join(buildDestinationFolder, 'jobs');
67
68
  buildDestinationDbFolder = path_1.default.join(buildDestinationFolder, 'db');
68
69
  buildDestinationDocsFolder = path_1.default.join(buildDestinationFolder, 'docs');
70
+ macroCorePath = (_a = process.env.macroCorePath) !== null && _a !== void 0 ? _a : '';
71
+ if (!(macroCorePath === '')) return [3 /*break*/, 2];
69
72
  return [4 /*yield*/, (0, utils_1.getNodeModulePath)('@sasjs/core')];
70
73
  case 1:
71
- macroCorePath = _a.sent();
74
+ // If no environment variable is set/populated then check for an installed
75
+ // @sasjs/core in locations known to node.
76
+ macroCorePath = _b.sent();
77
+ _b.label = 2;
78
+ case 2:
72
79
  buildDestinationResultsFolder = (0, utils_2.getAbsolutePath)(buildResultsFolder, isLocal ? process.projectDir : homeDir);
73
80
  buildDestinationResultsLogsFolder = path_1.default.join(buildDestinationResultsFolder, 'logs');
74
81
  sas9CredentialsError = 'The following attributes were not found:' +
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -66,8 +77,10 @@ var path_1 = __importDefault(require("path"));
66
77
  var configUtils = __importStar(require("../config"));
67
78
  var setConstants_1 = require("../setConstants");
68
79
  var fileModule = __importStar(require("@sasjs/utils/file"));
80
+ var utils = __importStar(require("../utils"));
69
81
  describe('setConstants', function () {
70
82
  var config;
83
+ var origProcessEnv = process.env;
71
84
  beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
72
85
  var _a, _b;
73
86
  return __generator(this, function (_c) {
@@ -82,13 +95,15 @@ describe('setConstants', function () {
82
95
  }
83
96
  });
84
97
  }); });
98
+ afterEach(function () {
99
+ process.env = __assign({}, origProcessEnv);
100
+ });
85
101
  test('should set constants inside appFolder when @sasjs/core dependency is present', function () { return __awaiter(void 0, void 0, void 0, function () {
86
- var appFolder, hasSasjsCore;
102
+ var hasSasjsCore;
87
103
  return __generator(this, function (_a) {
88
104
  switch (_a.label) {
89
105
  case 0:
90
- appFolder = ['some', 'app', 'folder'].join(path_1.default.sep);
91
- process.projectDir = appFolder;
106
+ process.projectDir = process.cwd();
92
107
  jest
93
108
  .spyOn(configUtils, 'getLocalOrGlobalConfig')
94
109
  .mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -99,11 +114,7 @@ describe('setConstants', function () {
99
114
  })];
100
115
  });
101
116
  }); });
102
- jest.spyOn(process, 'cwd').mockImplementation(function () { return appFolder; });
103
117
  hasSasjsCore = true;
104
- jest
105
- .spyOn(fileModule, 'folderExists')
106
- .mockImplementation(function (path) { return Promise.resolve(hasSasjsCore); });
107
118
  return [4 /*yield*/, (0, setConstants_1.setConstants)()];
108
119
  case 1:
109
120
  _a.sent();
@@ -119,6 +130,7 @@ describe('setConstants', function () {
119
130
  case 0:
120
131
  appFolder = ['some', 'app', 'folder'].join(path_1.default.sep);
121
132
  process.projectDir = appFolder;
133
+ process.env.macroCorePath = undefined;
122
134
  jest
123
135
  .spyOn(configUtils, 'getLocalOrGlobalConfig')
124
136
  .mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -130,11 +142,9 @@ describe('setConstants', function () {
130
142
  });
131
143
  }); });
132
144
  jest.spyOn(process, 'cwd').mockImplementation(function () { return appFolder; });
133
- jest
134
- .spyOn(fileModule, 'folderExists')
135
- .mockImplementation(function (folderPath) {
136
- return Promise.resolve(folderPath !== path_1.default.join(appFolder, 'node_modules', '@sasjs', 'core'));
137
- });
145
+ jest.spyOn(utils, 'getNodeModulePath').mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
146
+ return [2 /*return*/, ''];
147
+ }); }); });
138
148
  return [4 /*yield*/, (0, setConstants_1.setConstants)()];
139
149
  case 1:
140
150
  _a.sent();
@@ -147,6 +157,7 @@ describe('setConstants', function () {
147
157
  return __generator(this, function (_a) {
148
158
  switch (_a.label) {
149
159
  case 0:
160
+ process.env.macroCorePath = undefined;
150
161
  jest
151
162
  .spyOn(configUtils, 'getLocalOrGlobalConfig')
152
163
  .mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -157,6 +168,9 @@ describe('setConstants', function () {
157
168
  })];
158
169
  });
159
170
  }); });
171
+ jest.spyOn(utils, 'getNodeModulePath').mockImplementation(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
172
+ return [2 /*return*/, ''];
173
+ }); }); });
160
174
  return [4 /*yield*/, (0, setConstants_1.setConstants)(false)];
161
175
  case 1:
162
176
  _a.sent();
@@ -165,6 +179,63 @@ describe('setConstants', function () {
165
179
  }
166
180
  });
167
181
  }); });
182
+ test('should call getNodeModulePath once when environment variable macroCorePath is undefined', function () { return __awaiter(void 0, void 0, void 0, function () {
183
+ var getNodeModulePathSpy;
184
+ return __generator(this, function (_a) {
185
+ switch (_a.label) {
186
+ case 0:
187
+ process.env.macroCorePath = undefined;
188
+ getNodeModulePathSpy = jest
189
+ .spyOn(utils, 'getNodeModulePath')
190
+ .mockImplementation(function (packageName) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
191
+ return [2 /*return*/, Promise.resolve('')];
192
+ }); }); });
193
+ return [4 /*yield*/, (0, setConstants_1.setConstants)()];
194
+ case 1:
195
+ _a.sent();
196
+ expect(getNodeModulePathSpy).toHaveBeenCalledOnceWith('@sasjs/core');
197
+ return [2 /*return*/];
198
+ }
199
+ });
200
+ }); });
201
+ test('should call getNodeModulePath once when environment variable macroCorePath is blank', function () { return __awaiter(void 0, void 0, void 0, function () {
202
+ var getNodeModulePathSpy;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0:
206
+ process.env.macroCorePath = '';
207
+ getNodeModulePathSpy = jest
208
+ .spyOn(utils, 'getNodeModulePath')
209
+ .mockImplementation(function (packageName) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
210
+ return [2 /*return*/, Promise.resolve('')];
211
+ }); }); });
212
+ return [4 /*yield*/, (0, setConstants_1.setConstants)()];
213
+ case 1:
214
+ _a.sent();
215
+ expect(getNodeModulePathSpy).toHaveBeenCalledOnceWith('@sasjs/core');
216
+ return [2 /*return*/];
217
+ }
218
+ });
219
+ }); });
220
+ test('should not call getNodeModulePath when environment variable macroCorePath is populated', function () { return __awaiter(void 0, void 0, void 0, function () {
221
+ var getNodeModulePathSpy;
222
+ return __generator(this, function (_a) {
223
+ switch (_a.label) {
224
+ case 0:
225
+ process.env.macroCorePath = '../core';
226
+ getNodeModulePathSpy = jest
227
+ .spyOn(utils, 'getNodeModulePath')
228
+ .mockImplementation(function (packageName) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
229
+ return [2 /*return*/, Promise.resolve('')];
230
+ }); }); });
231
+ return [4 /*yield*/, (0, setConstants_1.setConstants)()];
232
+ case 1:
233
+ _a.sent();
234
+ expect(getNodeModulePathSpy).toBeCalledTimes(0);
235
+ return [2 /*return*/];
236
+ }
237
+ });
238
+ }); });
168
239
  });
169
240
  var verifySasjsConstants = function (appFolder, hasSasjsCore, isLocal) {
170
241
  if (hasSasjsCore === void 0) { hasSasjsCore = false; }
@@ -181,13 +252,16 @@ var verifySasjsConstants = function (appFolder, hasSasjsCore, isLocal) {
181
252
  expect(sasjsConstants.buildDestinationResultsFolder).toEqual(path_1.default.join(prefixAppFolder, isLocal ? '' : '.sasjs', 'sasjsresults'));
182
253
  expect(sasjsConstants.buildDestinationResultsLogsFolder).toEqual(path_1.default.join(prefixAppFolder, isLocal ? '' : '.sasjs', 'sasjsresults', 'logs'));
183
254
  expect(sasjsConstants.buildDestinationTestFolder).toEqual(path_1.default.join(prefixAppFolder, isLocal ? '' : '.sasjs', 'sasjsbuild', 'tests'));
184
- var corePath = hasSasjsCore
185
- ? 'core'
186
- : path_1.default.join('cli', 'node_modules', '@sasjs', 'core');
187
- if (appFolder) {
188
- expect(sasjsConstants.macroCorePath).toEqual(path_1.default.join(prefixAppFolder, 'node_modules', '@sasjs', corePath));
255
+ var corePath = hasSasjsCore ? 'core' : '';
256
+ if (hasSasjsCore) {
257
+ if (appFolder) {
258
+ expect(sasjsConstants.macroCorePath).toEqual(path_1.default.join(prefixAppFolder, 'node_modules', '@sasjs', corePath));
259
+ }
260
+ else {
261
+ expect(sasjsConstants.macroCorePath).toEqual(expect.toEndWith(corePath));
262
+ }
189
263
  }
190
264
  else {
191
- expect(sasjsConstants.macroCorePath).toEqual(expect.toEndWith(corePath));
265
+ expect(sasjsConstants.macroCorePath).toEqual(corePath);
192
266
  }
193
267
  };
@@ -684,35 +684,20 @@ var isSASjsProject = function () { return __awaiter(void 0, void 0, void 0, func
684
684
  }); };
685
685
  exports.isSASjsProject = isSASjsProject;
686
686
  var getNodeModulePath = function (module) { return __awaiter(void 0, void 0, void 0, function () {
687
- var projectPath, cliDepsPath, cliLocalPath, cliGlobalPath;
687
+ var nodePackagePath;
688
688
  return __generator(this, function (_a) {
689
- switch (_a.label) {
690
- case 0:
691
- projectPath = path_1.default.join(process.cwd(), 'node_modules', module);
692
- return [4 /*yield*/, (0, utils_1.folderExists)(projectPath)];
693
- case 1:
694
- if (_a.sent())
695
- return [2 /*return*/, projectPath
696
- // Check if module is present in @sasjs/cli located in project's dependencies
697
- ];
698
- cliDepsPath = path_1.default.join('@sasjs', 'cli', 'node_modules');
699
- cliLocalPath = path_1.default.join(process.cwd(), 'node_modules', cliDepsPath, module);
700
- return [4 /*yield*/, (0, utils_1.folderExists)(cliLocalPath)];
701
- case 2:
702
- if (_a.sent())
703
- return [2 /*return*/, cliLocalPath
704
- // Check if module is present in global @sasjs/cli
705
- ];
706
- cliGlobalPath = path_1.default.join(shelljs_1.default.exec("npm root -g", { silent: true }).stdout.replace(/\n/, ''), cliDepsPath, module);
707
- return [4 /*yield*/, (0, utils_1.folderExists)(cliGlobalPath)];
708
- case 3:
709
- if (_a.sent())
710
- return [2 /*return*/, cliGlobalPath
711
- // Return default value
712
- ];
713
- // Return default value
714
- return [2 /*return*/, ''];
689
+ // Look for ${module}/package.json, then return only the path
690
+ try {
691
+ nodePackagePath = path_1.default.dirname(require.resolve(path_1.default.join(module, 'package.json')));
692
+ if (nodePackagePath)
693
+ return [2 /*return*/, nodePackagePath];
694
+ }
695
+ catch (e) {
696
+ if (e.code !== 'MODULE_NOT_FOUND')
697
+ throw e;
715
698
  }
699
+ // Return default value
700
+ return [2 /*return*/, ''];
716
701
  });
717
702
  }); };
718
703
  exports.getNodeModulePath = getNodeModulePath;
package/package.json CHANGED
@@ -19,7 +19,6 @@
19
19
  "test:mocked": "jest --silent --runInBand --config=jest.config.js --coverage",
20
20
  "lint:fix": "npx prettier --write \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
21
21
  "lint": "npx prettier --check \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
22
- "preinstall": "npm run nodeVersionMessage",
23
22
  "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true",
24
23
  "doc": "npx compodoc -p tsconfig.doc.json --coverageTest 16 --coverageTestThresholdFail"
25
24
  },
@@ -51,7 +50,7 @@
51
50
  "access": "public"
52
51
  },
53
52
  "dependencies": {
54
- "@sasjs/adapter": "^4.16.0",
53
+ "@sasjs/adapter": "^4.16.1",
55
54
  "@sasjs/core": "4.59.9",
56
55
  "@sasjs/lint": "2.4.3",
57
56
  "@sasjs/utils": "3.5.2",
@@ -101,5 +100,5 @@
101
100
  "typescript": "4.9.5",
102
101
  "util": "0.12.4"
103
102
  },
104
- "version": "4.12.15"
103
+ "version": "4.12.16"
105
104
  }