jsii-rosetta 5.4.7-dev.0 → 5.4.7-dev.2

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/lib/fixtures.js CHANGED
@@ -160,7 +160,7 @@ function sidelineImports(source) {
160
160
  if (statement.kind === typescript_1.SyntaxKind.ImportDeclaration ||
161
161
  statement.kind === typescript_1.SyntaxKind.ImportEqualsDeclaration ||
162
162
  (statement.kind === typescript_1.SyntaxKind.VariableStatement &&
163
- statement.getChildAt(0).getChildAt(0).kind === typescript_1.SyntaxKind.DeclareKeyword)) {
163
+ statement.getChildAt(0)?.getChildAt(0)?.kind === typescript_1.SyntaxKind.DeclareKeyword)) {
164
164
  imports += statement.getFullText(sourceFile);
165
165
  }
166
166
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAClC,2CAAoF;AAEpF,uCAA8E;AAE9E;;GAEG;AACH,SAAgB,SAAS,CAAC,OAA0B,EAAE,KAAK,GAAG,KAAK;IACjE,IAAI,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACnC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAE5C,MAAM,SAAS,GAAG,UAAU,CAAC,2BAAiB,CAAC,kBAAkB,CAAC,CAAC;IACnE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,cAAc,GAAG,UAAU,CAAC,2BAAiB,CAAC,eAAe,CAAC,CAAC;IACrE,IAAI,cAAc,EAAE,CAAC;QACnB,mEAAmE;QACnE,uEAAuE;QACvE,IAAI,CAAC;YACH,MAAM,GAAG,kBAAkB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,yEAAyE;YACzE,IAAI,CAAC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AC1B,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,MAAc;IAIrC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE,yBAAY,CAAC,MAAM,EAAE,IAAI,EAAE,uBAAU,CAAC,EAAE,CAAC,CAAC;IAClG,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,IACE,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;YAC/C,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,uBAAuB;YACrD,CAAC,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;gBAC9C,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,uBAAU,CAAC,cAAc,CAAC,EAC3E,CAAC;YACD,OAAO,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,UAAU,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';\n\nimport { TypeScriptSnippet, SnippetParameters, ApiLocation } from './snippet';\n\n/**\n * Complete snippets with fixtures, if required\n */\nexport function fixturize(snippet: TypeScriptSnippet, loose = false): TypeScriptSnippet {\n let source = snippet.visibleSource;\n const parameters = snippet.parameters ?? {};\n\n const directory = parameters[SnippetParameters.$PROJECT_DIRECTORY];\n if (!directory) {\n return snippet;\n }\n\n const literateSource = parameters[SnippetParameters.LITERATE_SOURCE];\n if (literateSource) {\n // Compatibility with the \"old school\" example inclusion mechanism.\n // Completely load this file and attach a parameter with its directory.\n try {\n source = loadLiterateSource(directory, literateSource);\n } catch (ex) {\n // In loose mode, we ignore this failure and stick to the visible source.\n if (!loose) {\n throw ex;\n }\n }\n parameters[SnippetParameters.$COMPILATION_DIRECTORY] = path.join(directory, path.dirname(literateSource));\n } else if (parameters[SnippetParameters.FIXTURE]) {\n // Explicitly requested fixture must exist, unless we are operating in loose mode\n source = loadAndSubFixture(directory, snippet.location.api, parameters.fixture, source, !loose);\n } else if (parameters[SnippetParameters.NO_FIXTURE] === undefined) {\n // Don't explicitly request no fixture, load the default.\n source = loadAndSubFixture(directory, snippet.location.api, 'default', source, false);\n }\n\n return {\n ...snippet,\n completeSource: source,\n parameters,\n };\n}\n\nfunction loadLiterateSource(directory: string, literateFileName: string) {\n const fullPath = path.join(directory, literateFileName);\n const exists = fs.existsSync(fullPath);\n if (!exists) {\n // This couldn't really happen in practice, but do the check anyway\n throw new Error(`Sample uses literate source ${literateFileName}, but not found: ${fullPath}`);\n }\n return fs.readFileSync(fullPath).toString('utf-8');\n}\n\n/**\n * Load the fixture with the given name, and substitute the source into it\n *\n * If no fixture could be found and `mustExist` is true, and error will be thrown.\n *\n * In principle, the fixture we're looking for is `rosetta/FIXTURE.ts-fixture`.\n * However, we want to support an automatic transform of many small packages\n * combined into a single large package, perhaps into submodules (i.e., we want\n * to support monocdk), and in those cases the names of fixtures might conflict.\n * For example, all of them will have a `default.ts-fixture`, and there won't be\n * any explicit reference to that file anywhere... yet in the combined\n * monopackage we have to distinguish those fixtures.\n *\n * Therefore, we will consider submodule names as subdirectories, based on the\n * API location of the snippet we're fixturizing.\n *\n * (For example, the fixtures for a type called `monocdk.aws_s3.Bucket` will be\n * searched both in `rosetta/aws_s3/default.ts-fixture` as well as\n * `rosetta/default.ts-fixture`).\n */\nfunction loadAndSubFixture(\n directory: string,\n location: ApiLocation,\n fixtureName: string,\n source: string,\n mustExist: boolean,\n) {\n const candidates = fixtureCandidates(directory, fixtureName, location);\n const fixtureFileName = candidates.find((n) => fs.existsSync(n));\n\n if (!fixtureFileName) {\n if (mustExist) {\n throw new Error(`Sample uses fixture ${fixtureName}, but not found: ${JSON.stringify(candidates)}`);\n }\n return source;\n }\n\n const fixtureContents = fs.readFileSync(fixtureFileName, {\n encoding: 'utf-8',\n });\n\n const subRegex = /[/]{3}[ \\t]*here[ \\t]*$/im;\n if (!subRegex.test(fixtureContents)) {\n throw new Error(`Fixture does not contain '/// here': ${fixtureFileName}`);\n }\n\n const { imports, statements } = sidelineImports(source);\n const show = '/// !show';\n const hide = '/// !hide';\n\n const result = fixtureContents.replace(\n subRegex,\n [\n '// Code snippet begins after !show marker below',\n show,\n statements,\n hide,\n '// Code snippet ended before !hide marker above',\n ].join('\\n'),\n );\n\n return imports\n ? [\n '// Hoisted imports begin after !show marker below',\n show,\n imports,\n hide,\n '// Hoisted imports ended before !hide marker above',\n result,\n ].join('\\n')\n : result;\n}\n\nfunction fixtureCandidates(directory: string, fixtureName: string, location: ApiLocation): string[] {\n const ret = new Array<string>();\n const fileName = `${fixtureName}.ts-fixture`;\n const mods = submodules(location);\n\n ret.push(path.join(directory, 'rosetta', fileName));\n for (let i = 0; i < mods.length; i++) {\n ret.push(path.join(directory, 'rosetta', ...mods.slice(0, i + 1), fileName));\n }\n\n // Most specific one up front\n ret.reverse();\n return ret;\n}\n\n/**\n * Return the submodule parts from a given ApiLocation\n */\nfunction submodules(location: ApiLocation): string[] {\n switch (location.api) {\n case 'file':\n return [];\n case 'initializer':\n case 'member':\n case 'type':\n case 'parameter':\n return middle(location.fqn.split('.'));\n case 'moduleReadme':\n return location.moduleFqn.split('.').slice(1);\n }\n\n function middle(xs: string[]) {\n return xs.slice(1, xs.length - 1);\n }\n}\n\n/**\n * When embedding code fragments in a fixture, \"import\" statements must be\n * hoisted up to the top of the resulting document, as TypeScript only allows\n * those to be present in the top-level context of an ESM.\n *\n * @param source a block of TypeScript source\n *\n * @returns an object containing the import statements on one end, and the rest\n * on the other hand.\n */\nfunction sidelineImports(source: string): {\n imports: string;\n statements: string;\n} {\n let imports = '';\n let statements = '';\n\n const sourceFile = createSourceFile('index.ts', source, ScriptTarget.Latest, true, ScriptKind.TS);\n for (const statement of sourceFile.statements) {\n if (\n statement.kind === SyntaxKind.ImportDeclaration ||\n statement.kind === SyntaxKind.ImportEqualsDeclaration ||\n (statement.kind === SyntaxKind.VariableStatement &&\n statement.getChildAt(0).getChildAt(0).kind === SyntaxKind.DeclareKeyword)\n ) {\n imports += statement.getFullText(sourceFile);\n } else {\n statements += statement.getFullText(sourceFile);\n }\n }\n\n return { imports, statements };\n}\n"]}
1
+ {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAClC,2CAAoF;AAEpF,uCAA8E;AAE9E;;GAEG;AACH,SAAgB,SAAS,CAAC,OAA0B,EAAE,KAAK,GAAG,KAAK;IACjE,IAAI,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACnC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAE5C,MAAM,SAAS,GAAG,UAAU,CAAC,2BAAiB,CAAC,kBAAkB,CAAC,CAAC;IACnE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,cAAc,GAAG,UAAU,CAAC,2BAAiB,CAAC,eAAe,CAAC,CAAC;IACrE,IAAI,cAAc,EAAE,CAAC;QACnB,mEAAmE;QACnE,uEAAuE;QACvE,IAAI,CAAC;YACH,MAAM,GAAG,kBAAkB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,yEAAyE;YACzE,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AC,EAAY;QAC1B,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,MAAc;IAIrC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE,yBAAY,CAAC,MAAM,EAAE,IAAI,EAAE,uBAAU,CAAC,EAAE,CAAC,CAAC;IAClG,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,IACE,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;YAC/C,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,uBAAuB;YACrD,CAAC,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;gBAC9C,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,uBAAU,CAAC,cAAc,CAAC,EAC7E,CAAC;YACD,OAAO,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,UAAU,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';\n\nimport { TypeScriptSnippet, SnippetParameters, ApiLocation } from './snippet';\n\n/**\n * Complete snippets with fixtures, if required\n */\nexport function fixturize(snippet: TypeScriptSnippet, loose = false): TypeScriptSnippet {\n let source = snippet.visibleSource;\n const parameters = snippet.parameters ?? {};\n\n const directory = parameters[SnippetParameters.$PROJECT_DIRECTORY];\n if (!directory) {\n return snippet;\n }\n\n const literateSource = parameters[SnippetParameters.LITERATE_SOURCE];\n if (literateSource) {\n // Compatibility with the \"old school\" example inclusion mechanism.\n // Completely load this file and attach a parameter with its directory.\n try {\n source = loadLiterateSource(directory, literateSource);\n } catch (ex) {\n // In loose mode, we ignore this failure and stick to the visible source.\n if (!loose) {\n throw ex;\n }\n }\n parameters[SnippetParameters.$COMPILATION_DIRECTORY] = path.join(directory, path.dirname(literateSource));\n } else if (parameters[SnippetParameters.FIXTURE]) {\n // Explicitly requested fixture must exist, unless we are operating in loose mode\n source = loadAndSubFixture(directory, snippet.location.api, parameters.fixture, source, !loose);\n } else if (parameters[SnippetParameters.NO_FIXTURE] === undefined) {\n // Don't explicitly request no fixture, load the default.\n source = loadAndSubFixture(directory, snippet.location.api, 'default', source, false);\n }\n\n return {\n ...snippet,\n completeSource: source,\n parameters,\n };\n}\n\nfunction loadLiterateSource(directory: string, literateFileName: string) {\n const fullPath = path.join(directory, literateFileName);\n const exists = fs.existsSync(fullPath);\n if (!exists) {\n // This couldn't really happen in practice, but do the check anyway\n throw new Error(`Sample uses literate source ${literateFileName}, but not found: ${fullPath}`);\n }\n return fs.readFileSync(fullPath).toString('utf-8');\n}\n\n/**\n * Load the fixture with the given name, and substitute the source into it\n *\n * If no fixture could be found and `mustExist` is true, and error will be thrown.\n *\n * In principle, the fixture we're looking for is `rosetta/FIXTURE.ts-fixture`.\n * However, we want to support an automatic transform of many small packages\n * combined into a single large package, perhaps into submodules (i.e., we want\n * to support monocdk), and in those cases the names of fixtures might conflict.\n * For example, all of them will have a `default.ts-fixture`, and there won't be\n * any explicit reference to that file anywhere... yet in the combined\n * monopackage we have to distinguish those fixtures.\n *\n * Therefore, we will consider submodule names as subdirectories, based on the\n * API location of the snippet we're fixturizing.\n *\n * (For example, the fixtures for a type called `monocdk.aws_s3.Bucket` will be\n * searched both in `rosetta/aws_s3/default.ts-fixture` as well as\n * `rosetta/default.ts-fixture`).\n */\nfunction loadAndSubFixture(\n directory: string,\n location: ApiLocation,\n fixtureName: string,\n source: string,\n mustExist: boolean,\n) {\n const candidates = fixtureCandidates(directory, fixtureName, location);\n const fixtureFileName = candidates.find((n) => fs.existsSync(n));\n\n if (!fixtureFileName) {\n if (mustExist) {\n throw new Error(`Sample uses fixture ${fixtureName}, but not found: ${JSON.stringify(candidates)}`);\n }\n return source;\n }\n\n const fixtureContents = fs.readFileSync(fixtureFileName, {\n encoding: 'utf-8',\n });\n\n const subRegex = /[/]{3}[ \\t]*here[ \\t]*$/im;\n if (!subRegex.test(fixtureContents)) {\n throw new Error(`Fixture does not contain '/// here': ${fixtureFileName}`);\n }\n\n const { imports, statements } = sidelineImports(source);\n const show = '/// !show';\n const hide = '/// !hide';\n\n const result = fixtureContents.replace(\n subRegex,\n [\n '// Code snippet begins after !show marker below',\n show,\n statements,\n hide,\n '// Code snippet ended before !hide marker above',\n ].join('\\n'),\n );\n\n return imports\n ? [\n '// Hoisted imports begin after !show marker below',\n show,\n imports,\n hide,\n '// Hoisted imports ended before !hide marker above',\n result,\n ].join('\\n')\n : result;\n}\n\nfunction fixtureCandidates(directory: string, fixtureName: string, location: ApiLocation): string[] {\n const ret = new Array<string>();\n const fileName = `${fixtureName}.ts-fixture`;\n const mods = submodules(location);\n\n ret.push(path.join(directory, 'rosetta', fileName));\n for (let i = 0; i < mods.length; i++) {\n ret.push(path.join(directory, 'rosetta', ...mods.slice(0, i + 1), fileName));\n }\n\n // Most specific one up front\n ret.reverse();\n return ret;\n}\n\n/**\n * Return the submodule parts from a given ApiLocation\n */\nfunction submodules(location: ApiLocation): string[] {\n switch (location.api) {\n case 'file':\n return [];\n case 'initializer':\n case 'member':\n case 'type':\n case 'parameter':\n return middle(location.fqn.split('.'));\n case 'moduleReadme':\n return location.moduleFqn.split('.').slice(1);\n }\n\n function middle(xs: string[]) {\n return xs.slice(1, xs.length - 1);\n }\n}\n\n/**\n * When embedding code fragments in a fixture, \"import\" statements must be\n * hoisted up to the top of the resulting document, as TypeScript only allows\n * those to be present in the top-level context of an ESM.\n *\n * @param source a block of TypeScript source\n *\n * @returns an object containing the import statements on one end, and the rest\n * on the other hand.\n */\nfunction sidelineImports(source: string): {\n imports: string;\n statements: string;\n} {\n let imports = '';\n let statements = '';\n\n const sourceFile = createSourceFile('index.ts', source, ScriptTarget.Latest, true, ScriptKind.TS);\n for (const statement of sourceFile.statements) {\n if (\n statement.kind === SyntaxKind.ImportDeclaration ||\n statement.kind === SyntaxKind.ImportEqualsDeclaration ||\n (statement.kind === SyntaxKind.VariableStatement &&\n statement.getChildAt(0)?.getChildAt(0)?.kind === SyntaxKind.DeclareKeyword)\n ) {\n imports += statement.getFullText(sourceFile);\n } else {\n statements += statement.getFullText(sourceFile);\n }\n }\n\n return { imports, statements };\n}\n"]}
package/package.json CHANGED
@@ -84,7 +84,7 @@
84
84
  "main": "lib/index.js",
85
85
  "license": "Apache-2.0",
86
86
  "homepage": "https://aws.github.io/jsii",
87
- "version": "5.4.7-dev.0",
87
+ "version": "5.4.7-dev.2",
88
88
  "types": "lib/index.d.ts",
89
89
  "exports": {
90
90
  ".": "./lib/index.js",