oc 0.50.25 → 0.50.27

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cli/domain/get-mocked-plugins.d.ts +1 -1
  3. package/dist/cli/domain/get-mocked-plugins.js +8 -25
  4. package/dist/cli/domain/local.d.ts +1 -1
  5. package/dist/cli/domain/mock.d.ts +1 -1
  6. package/dist/cli/domain/mock.js +9 -14
  7. package/dist/cli/domain/ocConfig.d.ts +50 -0
  8. package/dist/cli/domain/ocConfig.js +60 -0
  9. package/dist/cli/domain/package-components.js +1 -0
  10. package/dist/cli/domain/registry.js +7 -10
  11. package/dist/cli/facade/dev.js +17 -1
  12. package/dist/cli/facade/mock.d.ts +2 -2
  13. package/dist/cli/facade/mock.js +3 -0
  14. package/dist/components/oc-client/_package/package.json +4 -4
  15. package/dist/components/oc-client/_package/server.js +1 -1
  16. package/dist/components/oc-client/package-lock.json +11382 -0
  17. package/dist/components/oc-client/package.json +1 -1
  18. package/dist/registry/routes/component-preview.js +3 -0
  19. package/dist/registry/views/partials/layout.js +2 -2
  20. package/dist/registry/views/preview.d.ts +1 -0
  21. package/dist/registry/views/preview.js +2 -1
  22. package/dist/registry/views/static/style.d.ts +1 -1
  23. package/dist/registry/views/static/style.js +4 -0
  24. package/dist/types.d.ts +6 -9
  25. package/logintervals.md +1 -1
  26. package/package.json +1 -1
  27. package/test-components/test/.cursor/rules/oc-project.mdc +335 -0
  28. package/test-components/test/oc-app.d.ts +1 -0
  29. package/test-components/test/package-lock.json +5053 -0
  30. package/test-components/test/package.json +25 -0
  31. package/test-components/test/public/logo.png +0 -0
  32. package/test-components/test/src/server.ts +66 -0
  33. package/test-components/test/src/styles.css +30 -0
  34. package/test-components/test/src/view.ts +46 -0
  35. package/test-components/test/tsconfig.json +17 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Change Log
2
2
 
3
+ ### v0.50.27
4
+ - [#1435](https://github.com/opencomponents/oc/pull/1435) Fix loading info correctly
5
+
6
+ ### v0.50.26
7
+ - [#1434](https://github.com/opencomponents/oc/pull/1434) add fallback client option and new oc.json section for dev
8
+
3
9
  ### v0.50.25
4
10
  - [#1433](https://github.com/opencomponents/oc/pull/1433) update oc client browser
5
11
 
@@ -7,5 +7,5 @@ interface PluginMock {
7
7
  execute: (...args: unknown[]) => unknown;
8
8
  };
9
9
  }
10
- export default function getMockedPlugins(logger: Logger, componentsDir: string): PluginMock[];
10
+ export default function getMockedPlugins(logger: Logger, componentsDir?: string): PluginMock[];
11
11
  export {};
@@ -5,9 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = getMockedPlugins;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
8
  const resources_1 = __importDefault(require("../../resources/"));
10
- const settings_1 = __importDefault(require("../../resources/settings"));
9
+ const ocConfig_1 = require("./ocConfig");
11
10
  const isMockValid = (plugin) => {
12
11
  const isFunction = typeof plugin === 'function';
13
12
  const isValidObject = !!plugin &&
@@ -56,34 +55,18 @@ const registerDynamicMocks = (ocJsonLocation, mocks, logger) => Object.entries(m
56
55
  };
57
56
  })
58
57
  .filter((pluginMock) => !!pluginMock);
59
- const findPath = (pathToResolve, fileName) => {
60
- const rootDir = fs_extra_1.default.realpathSync('.');
61
- const fileToResolve = node_path_1.default.join(pathToResolve, fileName);
62
- if (!fs_extra_1.default.existsSync(fileToResolve)) {
63
- if (pathToResolve === rootDir) {
64
- return undefined;
65
- }
66
- const getParent = (pathToResolve) => pathToResolve.split('/').slice(0, -1).join('/');
67
- const parentDir = pathToResolve ? getParent(pathToResolve) : rootDir;
68
- return findPath(parentDir, fileName);
69
- }
70
- return fileToResolve;
71
- };
72
58
  function getMockedPlugins(logger, componentsDir) {
73
59
  componentsDir = node_path_1.default.resolve(componentsDir || '.');
74
60
  let plugins = [];
75
- const ocJsonFileName = settings_1.default.configFile.src.replace('./', '');
76
- const ocJsonPath = findPath(componentsDir, ocJsonFileName);
77
- if (!ocJsonPath) {
78
- return plugins;
79
- }
80
- const content = fs_extra_1.default.readJsonSync(ocJsonPath);
81
- const ocJsonLocation = ocJsonPath.slice(0, -ocJsonFileName.length);
82
- if (!content.mocks || !content.mocks.plugins) {
61
+ const content = (0, ocConfig_1.getOcConfig)(componentsDir);
62
+ const ocJsonLocation = content.sourcePath
63
+ ? node_path_1.default.dirname(content.sourcePath)
64
+ : componentsDir;
65
+ if (!content.development?.plugins) {
83
66
  return plugins;
84
67
  }
85
68
  logger.warn(resources_1.default.messages.cli.REGISTERING_MOCKED_PLUGINS);
86
- plugins = plugins.concat(registerStaticMocks(content.mocks.plugins.static ?? {}, logger));
87
- plugins = plugins.concat(registerDynamicMocks(ocJsonLocation, content.mocks.plugins.dynamic ?? {}, logger));
69
+ plugins = plugins.concat(registerStaticMocks(content.development.plugins.static ?? {}, logger));
70
+ plugins = plugins.concat(registerDynamicMocks(ocJsonLocation, content.development.plugins.dynamic ?? {}, logger));
88
71
  return plugins;
89
72
  }
@@ -12,7 +12,7 @@ export default function local(): {
12
12
  templateType: string;
13
13
  }): Promise<void>;
14
14
  mock: (params: {
15
- targetType: string;
15
+ targetType: "plugin";
16
16
  targetValue: string;
17
17
  targetName: string;
18
18
  }) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  export default function mock(): (params: {
2
- targetType: string;
2
+ targetType: "plugin";
3
3
  targetValue: string;
4
4
  targetName: string;
5
5
  }) => Promise<void>;
@@ -6,28 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = mock;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const settings_1 = __importDefault(require("../../resources/settings"));
9
+ const ocConfig_1 = require("./ocConfig");
10
10
  function mock() {
11
11
  return async (params) => {
12
- const localConfig = await fs_extra_1.default
13
- .readJson(settings_1.default.configFile.src)
14
- .catch(() => ({}));
15
- const mockType = params.targetType + 's';
16
- if (!localConfig.mocks) {
17
- localConfig.mocks = {};
18
- }
19
- if (!localConfig.mocks[mockType]) {
20
- localConfig.mocks[mockType] = {};
12
+ const localConfig = (0, ocConfig_1.getOcConfig)();
13
+ const mockType = `${params.targetType}s`;
14
+ if (!localConfig.development[mockType]) {
15
+ localConfig.development[mockType] = {};
21
16
  }
22
17
  let pluginType = 'static';
23
18
  if (fs_extra_1.default.existsSync(node_path_1.default.resolve(params.targetValue.toString()))) {
24
19
  pluginType = 'dynamic';
25
20
  }
26
- if (!localConfig.mocks[mockType][pluginType]) {
27
- localConfig.mocks[mockType][pluginType] = {};
21
+ if (!localConfig.development[mockType][pluginType]) {
22
+ localConfig.development[mockType][pluginType] = {};
28
23
  }
29
- localConfig.mocks[mockType][pluginType][params.targetName] =
24
+ localConfig.development[mockType][pluginType][params.targetName] =
30
25
  params.targetValue;
31
- return fs_extra_1.default.writeJson(settings_1.default.configFile.src, localConfig, { spaces: 2 });
26
+ return (0, ocConfig_1.setOcConfig)(localConfig);
32
27
  };
33
28
  }
@@ -0,0 +1,50 @@
1
+ export interface OpenComponentsConfig {
2
+ /** JSON schema specification reference */
3
+ $schema?: string | null;
4
+ /** List of registry URLs where components will be published */
5
+ registries?: string[];
6
+ /** Development-specific configuration settings */
7
+ development?: {
8
+ /** Fallback configuration for when components cannot be found locally */
9
+ fallback?: {
10
+ /** URL of the fallback registry to use when components cannot be found locally */
11
+ url: string;
12
+ /** Whether to use the fallback registry's oc-client-browser.js for previewing components */
13
+ client?: boolean;
14
+ };
15
+ /** Plugin mocking configuration for development */
16
+ plugins?: {
17
+ /** Dynamic plugin mocks - file paths to JavaScript modules */
18
+ dynamic?: Record<string, string>;
19
+ /** Static plugin mocks - static values that will always be returned */
20
+ static?: Record<string, string>;
21
+ };
22
+ };
23
+ /** @deprecated Use development.plugins instead */
24
+ mocks?: {
25
+ /** @deprecated Use development.plugins instead */
26
+ plugins?: {
27
+ /** @deprecated Use development.plugins.dynamic instead */
28
+ dynamic?: Record<string, string>;
29
+ /** @deprecated Use development.plugins.static instead */
30
+ static?: Record<string, string>;
31
+ };
32
+ };
33
+ }
34
+ type ParsedConfig = {
35
+ sourcePath?: string;
36
+ registries: string[];
37
+ development: {
38
+ plugins: {
39
+ dynamic?: Record<string, string>;
40
+ static?: Record<string, string>;
41
+ };
42
+ fallback?: {
43
+ url: string;
44
+ client?: boolean;
45
+ };
46
+ };
47
+ };
48
+ export declare function getOcConfig(folder?: string): ParsedConfig;
49
+ export declare function setOcConfig(config: ParsedConfig, path?: string): void;
50
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOcConfig = getOcConfig;
7
+ exports.setOcConfig = setOcConfig;
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const settings_1 = __importDefault(require("../../resources/settings"));
11
+ const findPath = (pathToResolve, fileName) => {
12
+ const rootDir = node_fs_1.default.realpathSync('.');
13
+ const fileToResolve = node_path_1.default.join(pathToResolve, fileName);
14
+ if (!node_fs_1.default.existsSync(fileToResolve)) {
15
+ if (pathToResolve === rootDir) {
16
+ return undefined;
17
+ }
18
+ const getParent = (pathToResolve) => pathToResolve.split('/').slice(0, -1).join('/');
19
+ const parentDir = pathToResolve ? getParent(pathToResolve) : rootDir;
20
+ return findPath(parentDir, fileName);
21
+ }
22
+ return fileToResolve;
23
+ };
24
+ function parseConfig(config) {
25
+ const plugins = {
26
+ ...(config.mocks?.plugins || {}),
27
+ ...(config.development?.plugins || {})
28
+ };
29
+ const parsedConfig = {
30
+ ...config,
31
+ registries: config.registries || [],
32
+ development: {
33
+ plugins,
34
+ fallback: config.development?.fallback
35
+ }
36
+ };
37
+ return parsedConfig;
38
+ }
39
+ function getOcConfig(folder) {
40
+ const configPath = folder
41
+ ? findPath(folder, settings_1.default.configFile.src.replace('./', '')) ||
42
+ settings_1.default.configFile.src
43
+ : settings_1.default.configFile.src;
44
+ try {
45
+ const config = JSON.parse(node_fs_1.default.readFileSync(configPath, 'utf8'));
46
+ return { ...parseConfig(config), sourcePath: configPath };
47
+ }
48
+ catch {
49
+ return {
50
+ registries: [],
51
+ development: {
52
+ plugins: {}
53
+ }
54
+ };
55
+ }
56
+ }
57
+ function setOcConfig(config, path) {
58
+ const { sourcePath, ...rest } = config;
59
+ node_fs_1.default.writeFileSync(path || sourcePath || settings_1.default.configFile.src, JSON.stringify(rest, null, 2));
60
+ }
@@ -93,6 +93,7 @@ const packageComponents = () => async (options) => {
93
93
  verbose,
94
94
  production
95
95
  };
96
+ console.log('compiling component', componentPath);
96
97
  const ocTemplate = (0, require_template_1.default)(type, {
97
98
  compiler: true,
98
99
  componentPath
@@ -44,6 +44,7 @@ const urlBuilder = __importStar(require("../../registry/domain/url-builder"));
44
44
  const settings_1 = __importDefault(require("../../resources/settings"));
45
45
  const put_1 = __importDefault(require("../../utils/put"));
46
46
  const urlParser = __importStar(require("../domain/url-parser"));
47
+ const ocConfig_1 = require("./ocConfig");
47
48
  const getOcVersion = () => {
48
49
  const ocPackagePath = node_path_1.default.join(__dirname, '../../../package.json');
49
50
  const ocInfo = fs_extra_1.default.readJsonSync(ocPackagePath);
@@ -66,16 +67,14 @@ function registry(opts = {}) {
66
67
  throw 'oc registry not available';
67
68
  if (apiResponse.type !== 'oc-registry')
68
69
  throw 'not a valid oc registry';
69
- const res = await fs_extra_1.default
70
- .readJson(settings_1.default.configFile.src)
71
- .catch(() => ({}));
70
+ const res = (0, ocConfig_1.getOcConfig)();
72
71
  if (!res.registries) {
73
72
  res.registries = [];
74
73
  }
75
74
  if (!res.registries.includes(registry)) {
76
75
  res.registries.push(registry);
77
76
  }
78
- return fs_extra_1.default.writeJson(settings_1.default.configFile.src, res);
77
+ return (0, ocConfig_1.setOcConfig)(res);
79
78
  }
80
79
  catch {
81
80
  throw 'oc registry not available';
@@ -86,7 +85,7 @@ function registry(opts = {}) {
86
85
  return [opts.registry];
87
86
  }
88
87
  try {
89
- const res = await fs_extra_1.default.readJson(settings_1.default.configFile.src);
88
+ const res = (0, ocConfig_1.getOcConfig)();
90
89
  if (!res.registries || res.registries.length === 0)
91
90
  throw 'No oc registries';
92
91
  return res.registries;
@@ -142,11 +141,9 @@ function registry(opts = {}) {
142
141
  if (registry.slice(registry.length - 1) !== '/') {
143
142
  registry += '/';
144
143
  }
145
- const res = await fs_extra_1.default
146
- .readJson(settings_1.default.configFile.src)
147
- .catch(() => ({ registries: [] }));
148
- res.registries = res.registries.filter((x) => x !== registry);
149
- await fs_extra_1.default.writeJson(settings_1.default.configFile.src, res);
144
+ const res = (0, ocConfig_1.getOcConfig)();
145
+ res.registries = res.registries?.filter((x) => x !== registry) || [];
146
+ (0, ocConfig_1.setOcConfig)(res);
150
147
  }
151
148
  };
152
149
  }
@@ -46,6 +46,7 @@ const oc = __importStar(require("../../index"));
46
46
  const index_1 = __importDefault(require("../../resources/index"));
47
47
  const get_mocked_plugins_1 = __importDefault(require("../domain/get-mocked-plugins"));
48
48
  const handle_dependencies_1 = __importDefault(require("../domain/handle-dependencies"));
49
+ const ocConfig_1 = require("../domain/ocConfig");
49
50
  const watch_1 = __importDefault(require("../domain/watch"));
50
51
  const cliMessages = index_1.default.messages.cli;
51
52
  const cliErrors = index_1.default.errors.cli;
@@ -55,7 +56,21 @@ const dev = ({ local, logger }) => (0, universalify_1.fromPromise)(async (opts)
55
56
  const componentsDir = opts.dirPath;
56
57
  const port = opts.port || 3000;
57
58
  const baseUrl = opts.baseUrl || `http://localhost:${port}/`;
58
- const fallbackRegistryUrl = opts.fallbackRegistryUrl;
59
+ let fallbackRegistryUrl = opts.fallbackRegistryUrl;
60
+ let fallbackClient = false;
61
+ if (!fallbackRegistryUrl) {
62
+ try {
63
+ const localConfig = (0, ocConfig_1.getOcConfig)(componentsDir);
64
+ if (!fallbackRegistryUrl &&
65
+ typeof localConfig.development?.fallback?.url === 'string') {
66
+ fallbackRegistryUrl = localConfig.development?.fallback?.url;
67
+ }
68
+ fallbackClient = !!localConfig.development?.fallback?.client;
69
+ }
70
+ catch {
71
+ // Config file doesn't exist or is invalid, continue without fallback
72
+ }
73
+ }
59
74
  const hotReloading = typeof opts.hotReloading === 'undefined' ? true : opts.hotReloading;
60
75
  const optWatch = typeof opts.watch === 'undefined' ? true : opts.watch;
61
76
  let packaging = false;
@@ -167,6 +182,7 @@ const dev = ({ local, logger }) => (0, universalify_1.fromPromise)(async (opts)
167
182
  discovery: true,
168
183
  env: { name: 'local' },
169
184
  fallbackRegistryUrl,
185
+ fallbackClient,
170
186
  hotReloading,
171
187
  liveReloadPort: liveReload.port,
172
188
  local: true,
@@ -5,12 +5,12 @@ declare const mock: ({ local, logger }: {
5
5
  logger: Logger;
6
6
  }) => {
7
7
  (opts: {
8
- targetType: string;
8
+ targetType: "plugin";
9
9
  targetValue: string;
10
10
  targetName: string;
11
11
  }): Promise<void>;
12
12
  (opts: {
13
- targetType: string;
13
+ targetType: "plugin";
14
14
  targetValue: string;
15
15
  targetName: string;
16
16
  }, arguments__1: (error: unknown, value: void) => void): void;
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const universalify_1 = require("universalify");
7
7
  const index_1 = __importDefault(require("../../resources/index"));
8
8
  const mock = ({ local, logger }) => (0, universalify_1.fromPromise)(async (opts) => {
9
+ if (opts.targetType !== 'plugin') {
10
+ throw new Error('targetType must be "plugin"');
11
+ }
9
12
  await local.mock(opts);
10
13
  logger.ok(index_1.default.messages.cli.MOCKED_PLUGIN(opts.targetName, opts.targetValue));
11
14
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oc-client",
3
3
  "description": "The OpenComponents client-side javascript client",
4
- "version": "0.50.25",
4
+ "version": "0.50.27",
5
5
  "repository": "https://github.com/opencomponents/oc/tree/master/components/oc-client",
6
6
  "author": "Matteo Figus <matteofigus@gmail.com>",
7
7
  "oc": {
@@ -22,14 +22,14 @@
22
22
  ],
23
23
  "dataProvider": {
24
24
  "type": "node.js",
25
- "hashKey": "91d64b9ede5ef940193c697620df913d73559409",
25
+ "hashKey": "8f29903f1d53f460ce634ecf007a25b1bd3f1cee",
26
26
  "src": "server.js",
27
27
  "size": 613
28
28
  }
29
29
  },
30
- "version": "0.50.25",
30
+ "version": "0.50.27",
31
31
  "packaged": true,
32
- "date": 1756131708213
32
+ "date": 1756270183453
33
33
  },
34
34
  "devDependencies": {
35
35
  "oc-template-es6-compiler": "^1.0.1"
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(t,s)=>{const{staticPath:e,templates:a}=t;return s(null,{staticPath:e,templates:a})},o=(t,s)=>{r(t,(e,a)=>{if(e)return s(e);if(a==null)return s(null,{__oc_emptyResponse:!0});const n=t.action?a:Object.assign({},a,{_staticPath:t.staticPath,_baseUrl:t.baseUrl,_componentName:"oc-client",_componentVersion:"0.50.25"}),c=t.staticPath.indexOf("http")===0?t.staticPath:"https:"+t.staticPath;return s(null,Object.assign({},{component:{key:"8b7545cba94f7c029b9d46108bfe8e4e6040ea09",src:c+"template.js",props:n}}))})};exports.data=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(t,s)=>{const{staticPath:e,templates:a}=t;return s(null,{staticPath:e,templates:a})},o=(t,s)=>{r(t,(e,a)=>{if(e)return s(e);if(a==null)return s(null,{__oc_emptyResponse:!0});const n=t.action?a:Object.assign({},a,{_staticPath:t.staticPath,_baseUrl:t.baseUrl,_componentName:"oc-client",_componentVersion:"0.50.27"}),c=t.staticPath.indexOf("http")===0?t.staticPath:"https:"+t.staticPath;return s(null,Object.assign({},{component:{key:"8b7545cba94f7c029b9d46108bfe8e4e6040ea09",src:c+"template.js",props:n}}))})};exports.data=o;