{"id":20466916,"url":"https://github.com/fwh1990/this-file","last_synced_at":"2025-04-13T09:10:53.301Z","repository":{"id":143796445,"uuid":"369056588","full_name":"fwh1990/this-file","owner":"fwh1990","description":"Create dynamic __dirname, __filename and require method for both ESM and CJS","archived":false,"fork":false,"pushed_at":"2021-06-09T06:13:10.000Z","size":67,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-13T21:54:59.450Z","etag":null,"topics":["es-modules","esm-dirname","esm-filename","esm-require"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fwh1990.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-05-20T02:28:31.000Z","updated_at":"2024-01-31T23:24:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"562e035a-429b-49a4-922a-9d4e5c674d7c","html_url":"https://github.com/fwh1990/this-file","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"4d11887c8255600654b01d4f4e1236cd7eb0d764"},"previous_names":["fwh1990/node-rootdir"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fwh1990%2Fthis-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fwh1990%2Fthis-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fwh1990%2Fthis-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fwh1990%2Fthis-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fwh1990","download_url":"https://codeload.github.com/fwh1990/this-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247878256,"owners_count":21011218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es-modules","esm-dirname","esm-filename","esm-require"],"created_at":"2024-11-15T13:26:22.837Z","updated_at":"2025-04-13T09:10:53.278Z","avatar_url":"https://github.com/fwh1990.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# this-file\n\nIf you are an author of open source repository, you may want to support both CJS and ESM for users since it's a confused period. It's hard to use `__dirname` and `import.meta.url` in one file specially for typescript project.\n\n# Installation\n\n```bash\nyarn add this-file\n```\n\n# Usage\n\n```typescript\n// In per file\nimport { createContext } from 'this-file';\n\nconst context = createContext();\n\n// CJS\ncontext.filename IS __filename\ncontext.dirname IS __dirname\ncontext.require IS require\n\n// ESM\ncontext.filename IS url.fileURLToPath(import.meta.url)\ncontext.dirname IS path.dirname(context.filename)\ncontext.require IS module.createContext(import.meta.url)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffwh1990%2Fthis-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffwh1990%2Fthis-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffwh1990%2Fthis-file/lists"}