Skip to content

Commit

Permalink
fix: hmm?
Browse files Browse the repository at this point in the history
  • Loading branch information
gustaveWPM committed Feb 26, 2024
1 parent 42d4c1c commit 0820b57
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = {
'no-unreachable': ERROR,
'require-await': ERROR,
'no-unused-vars': OFF,
'import/first': ERROR
'import/first': ERROR,
'no-eval': ERROR
},

extends: [
Expand Down
2 changes: 1 addition & 1 deletion doc/i18n/00.quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vocabulary, since avoiding hard-coded duplicate values is essential in such data
Another motivation was also to maintain a _prebuilder_ code that is as simple and predictable as possible.

The _prebuilder_ is a standalone NPM package. It does not "import" any scripts from the codebase. Instead, it opens them as files via the _filesystem_
and juggles between parsing and raw `eval` function calls (which could be also `JSON.parse` calls... but still).
and juggles between parsing and raw (but well delimited) `eval` function calls.

The ability to dynamically define values based on variables scattered in different parts of the code made implementing this feature nightmarish. In my
opinion, this indicated a poor design choice rather than a flawed implementation of the _prebuilder_.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateBlogArchitectureType from '../blogArchitectureType';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/blog/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateBlogType from '../blogType';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/blog/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateI18nBlogCategories from '../i18nBlogCategories';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/blog/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateI18nPagesTitles from '../i18nPagesTitles';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/blog/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateDefaultLanguageTokenType from '../defaultLanguageTokenType';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/defaultLanguageToken/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateIndexFile from '../indexFile';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/index/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { afterAll, describe, expect, it } from 'vitest';

import generateLandingPagesType from '../lpType';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/lp/__tests__/FAKE_CODEGEN';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Page } from '../../../types/Metadatas';

import generatePagesType, { HARDCODED_FALLBACK_TYPE_FIELDS } from '../pagesType';

// https://github.com/vitest-dev/vitest/discussions/2484
const fs = require('fs/promises');

const __TARGET_FOLDER_ROOT = './packages/prebuilder/src/generators/pages/__tests__/FAKE_CODEGEN';
Expand Down
10 changes: 5 additions & 5 deletions packages/prebuilder/src/lib/__tests__/prebuild.etc.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { describe, expect, it } from 'vitest';

import getRawDataFromBracesDeclaration from '../getRawDataFromBracesDeclaration';
import { objInnerToObj } from '../etc';

describe('objInnerToObj', () => {
it('should return an obj, given a valid obj inner', () => {
const objInner = `
foo: 'bar',
bar: 'foo',
`;
expect(objInnerToObj(objInner)).toStrictEqual({ foo: 'bar', bar: 'foo' });
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const objInner = getRawDataFromBracesDeclaration(JSON.stringify({ foo: 'bar', bar: 'foo' }), 0);
expect(objInner).not.toBe(null);
expect(objInnerToObj(objInner as string)).toStrictEqual({ foo: 'bar', bar: 'foo' });
});
});
6 changes: 5 additions & 1 deletion packages/prebuilder/src/lib/etc.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// eslint-disable-next-line
/**
* @danger {Eval}
* NOTE: this function is DANGEROUS, use it wise and NEVER just send it an unchecked string.
*/
// eslint-disable-next-line no-eval
export const objInnerToObj = (objInner: string): any => eval('({\n' + objInner + '\n})');
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { INVALID_NESTINGS_NEEDLE, INVALID_NESTING_NEEDLE, INVALID_SLUGS_NEEDLE,
import { describe, expect, it, vi } from 'vitest';
// eslint-disable-next-line import/no-extraneous-dependencies
import { INVALID_PATH } from '𝕍/commons';
import path from 'path';

import type { VocabKey } from '../../config/translations';

import formatMessage from '../../config/formatMessage';
import sysPagesValidator from '../sysPages';

// https://github.com/vitest-dev/vitest/discussions/2484
const path = require('path');

const VALID_PAGES_FOLDER = path.normalize('./packages/prebuilder/src/validators/__tests__/fake_pages_folders/valid_fake_pages_folder');

const VALID_PAGES_FOLDER_WITH_ONE_UGLY_INDEX_STRATEGY = path.normalize(
Expand Down

0 comments on commit 0820b57

Please sign in to comment.