@blocklet/pages-kit-block-studio 0.4.133 → 0.4.135

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.
@@ -32,15 +32,18 @@ export function setBlockEntryFilesPattern(pattern) {
32
32
  export function getBlockEntryFilesPattern() {
33
33
  return process.env.BLOCK_ENTRY_FILES_PATTERN || DEFAULT_BLOCK_ENTRY_FILES_PATTERN;
34
34
  }
35
+ export function getWatchFilesDir() {
36
+ return process.env.WATCH_FILES_DIR;
37
+ }
35
38
  export function findComponentFiles(options = {}) {
36
- const { cwd = process.cwd(), filter } = options;
39
+ const { cwd = process.cwd(), filter, strictExist = true } = options;
37
40
  const files = globSync(getBlockEntryFilesPattern(), { cwd });
38
41
  return files
39
42
  .map((file) => {
40
43
  const blockName = getBlockName(file);
41
44
  const fullPath = path.resolve(cwd, file);
42
45
  const isHtml = file.endsWith('.html');
43
- const metadata = initializeMetadata(fullPath);
46
+ const metadata = initializeMetadata(fullPath, strictExist);
44
47
  return {
45
48
  file,
46
49
  blockName,
@@ -49,7 +52,7 @@ export function findComponentFiles(options = {}) {
49
52
  metadata,
50
53
  };
51
54
  })
52
- .filter(({ blockName }) => !filter?.length || filter.includes(blockName || ''));
55
+ .filter(({ blockName, metadata }) => metadata?.id && (!filter?.length || filter.includes(blockName || '')));
53
56
  }
54
57
  export function getBlockName(entry) {
55
58
  // First try to match index.{ts,tsx,html} pattern
@@ -68,8 +71,10 @@ export function getBlockName(entry) {
68
71
  }
69
72
  export const isPathSafe = (filePath) => {
70
73
  const normalizedPath = path.normalize(filePath);
71
- const pwd = process.env.PWD || process.cwd();
72
- return (!normalizedPath.includes('../') && !normalizedPath.includes('..\\') && path.resolve(normalizedPath).startsWith(pwd));
74
+ const watchFilesDir = getWatchFilesDir() || process.cwd();
75
+ return (!normalizedPath.includes('../') &&
76
+ !normalizedPath.includes('..\\') &&
77
+ path.resolve(normalizedPath).startsWith(watchFilesDir));
73
78
  };
74
79
  export const isDev = process.env.BLOCKLET_MODE === 'development';
75
80
  export const isMetadataFile = (filePath) => {
@@ -104,7 +109,7 @@ export const downloadAsset = async ({ asset, savePath, componentDid, }) => {
104
109
  export const getPreviewImageRelativePath = (name) => {
105
110
  return path.join(PREVIEW_IMAGE_DIR, name);
106
111
  };
107
- export function initializeMetadata(tempFilePath) {
112
+ export function initializeMetadata(tempFilePath, strictExist = false) {
108
113
  let content = '';
109
114
  if (!tempFilePath) {
110
115
  throw new Error('File path is required');
@@ -117,6 +122,9 @@ export function initializeMetadata(tempFilePath) {
117
122
  if (fs.existsSync(filePath)) {
118
123
  content = fs.readFileSync(filePath, 'utf-8');
119
124
  }
125
+ else if (strictExist) {
126
+ return null;
127
+ }
120
128
  let metadata = {};
121
129
  if (content) {
122
130
  try {
@@ -7,5 +7,6 @@ export declare function initBlockStudioPlugins(options?: {
7
7
  transpileBuiltinModule?: boolean;
8
8
  ignoreNodePolyfills?: boolean;
9
9
  ignoreSplitEditComponent?: boolean;
10
+ watchFilesDir?: string;
10
11
  }): Plugin[];
11
12
  export default initBlockStudioPlugins;